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).
Possible? Absolutely.
Do you care? Not a bit. Not unless you overrode setEnabled:
in a subclass and you are the one making the retain
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:
- (id)initWithData:(NSMutableArray *) {
UITextView *myText;
if ( ( self = [super init] ) ) {
myText = [[UITextView alloc] initWithFrame:aRect]; // rc +1
[myText setEnabled:NO]; // rc change irrelevant
[self addSubview:myText]; // rc change irrelevant
[myText release]; // rc -1
}
}
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!