Possible Duplicate:
Reference count is still 1 after [obj release], when it should be deallocated
1.When i write this code.
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 100, 30)];
[self.view addSubview:label];
label.text =@"label Text";
[label release];
[label release];
NSLog(@"LableRetainCount = %i \n",lable.retainCount);
Output: LableRetainCount 1.Lable retain count not decrease from 1 why?
2.When i write this code .
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 100, 30)];
[self.view addSubview:lable];
label.text =@"lable Text";
label = nil;
NSLog(@"LabelRetainCount = %i \n",label.retainCount);
Output : LabelRetainCount = 0 When i set “label = nil” it’s retain count become 0 why?
it is meanes memory deallocated of this object?
- Object released or not?
- Now we are not need release it?
- The retainCount method can never return 0.It is means object alive after release?
in #2 it returns 0 because you set your label pointer to nil, which is 0, and when you call a function on nil it returns nil, ie 0. So its not really returning a retainCount its just returning nil. You have to understand after you set label to nil that it is no longer pointing at your UILabel…
On #1 if you wanted to properly release it, like all the way to 0, first you would do this after your .text line:
Then your retain count should be 0 and the object will be released.