Hi. Im just beginner with objective c. I have a some problems with memory management. In here is some example code:
In the same method:
-(void)doSomething{
NSString *strTxt = @"This is txt";
NSString *strTxt2 = @"This is txt2";
The question is, when im printing strTxt to NSLog, has its memory alloc released already or did removeObjectAtIndex release only maAllTxt object at index 0? Is it the same with replaceObjectAtIndex- method?
Second question is, what is the difference with "self.variable" and "variable" if variable have add to class header file?
Last edited by Alec; 03-11-2010 at 01:03 PM.
Reason: error fix
BTW, there is a mistake in your code - make sure you have nil as the final element in initWithObjects.
NSMutableArray *maAllTxt = [NSMutableArray alloc] initWithObjects:strTxt, strTxt2, nil];
Also, there is a memory leak in there as maAllTxt is never released. You seem pretty confused about memory management - maybe you should read a relevant chapter in a good iPhone dev book.
self.variable uses the setter/getter whilst variable accesses your variable directly.
I recommend to always use self.variable as this makes sure that, when the value changes, the old content is released and the new one retained.
Also, can you please consider changing your signature - I believe you're trying too hard to sell and forgot us, the poor users that are reading this forum.
Also, can you please consider changing your signature - I believe you're trying too hard to sell and forgot us, the poor users that are reading this forum.
Sorry... quoted the wrong part in my last reply.. I meant to quote this...
"I recommend to always use self.variable as this makes sure that, when the value changes, the old content is released and the new one retained. "
I wasn't aware that one would run the risk of not releasing something using direct access.