UITextView setEnabled:导致保留计数增加?
我有一个 UITextView,它的文本集来自局部变量。在此之后是否有可能:
[textView setEnabled:NO];
保留计数增加一?
编辑:
“问题”,如果它是一个问题,是在一个小视图的构造函数中:
- (id)initWithData:(NSMutableArray *) {
UITextView *myText;
if ( ( self = [super init] ) ) {
myText = [[UITextView alloc] initWithFrame:aRect];
// retain count = 1;
[myText setEnabled:NO]; // retain count 2
[self addSubview:myText]; // retain count 3
[myText release]; // retain count 2
}
}
现在,我已经“自动释放”了文本视图,但我不确定内存是否管理良好(该帖子与此问题相关)。
I have a UITextView which has its text sets from a local variable. Is it possible that after this:
[textView setEnabled:NO];
The retain count gets incremented by one?
EDIT:
The "problem", if it is a problem, is in the constructor of a small view:
- (id)initWithData:(NSMutableArray *) {
UITextView *myText;
if ( ( self = [super init] ) ) {
myText = [[UITextView alloc] initWithFrame:aRect];
// retain count = 1;
[myText setEnabled:NO]; // retain count 2
[self addSubview:myText]; // retain count 3
[myText release]; // retain count 2
}
}
Now, I've "autoreleased" the text view, but I'm not sure if the memory is well managed (the post is related to this question).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能的?绝对地。
你关心吗?一点也不。除非您在子类中覆盖
setEnabled:
并且您是进行retain
调用的人,否则不会。如果是,则它是框架中的实现细节。
将保留计数视为增量,而不是绝对数字。绝对值没有意义。因此:
所以,是的,你已经正确地管理了内存;在
myText
局部变量范围的末尾,所有保留都已通过释放进行了平衡。当您
addSubview:
时,该方法是否保留该对象或复制它是一个与此范围内的内存管理无关的实现细节。显然,子视图维护引用并保留它对于其目的来说是必要的,但这是超出此方法内存管理范围的实现细节!Possible? Absolutely.
Do you care? Not a bit. Not unless you overrode
setEnabled:
in a subclass and you are the one making theretain
call.If it is, it is an implementation detail in the frameworks.
Think about retain counts as deltas, not as absolute numbers. The absolute value is meaningless. Thus:
So, yes, you have managed memory correctly; at the end of the scope of the
myText
local variable, all retains have been balanced by releases.When you
addSubview:
, whether that method retains the object or makes a copy of it is an implementation detail that isn't relevant to memory management in this scope. Obviously, that the subview maintains a reference and retains it is necessary for its purposes, but that is an implementation detail beyond the scope of this method's memory management!