Regarding this post: iPhone - dealloc - Release vs. noil
1) [foo release]; 2) self.bar = nil;
The explanation was as follows:
Releases an object by accessing it through the instance variable panel. The instance variable will become a dangling pointer. This is the preferred method in dealloc.
Assigns the nil property bar to itself, which in practice frees up anything that currently saves the property. Do this if you have a custom parameter for the property, which should clear more than just an instance variable that supports the property.
Can someone clarify explanation # 1? Access through the instance variable panel?
For example, I set private var to the title of my object like this:
SomeObject *oPointer;
I do not use the setter property with this pointer in the header file, and when creating an instance of the object, it synthesizes NOT .
In my code, under certain conditions, I then have to select and assign this pointer to this object.
obj = [[SomeObject alloc] initWith....];
So now this is done through the obj instance variable. I have a UIButton that is configured to RESET this object that it attached disables it. I do this through:
[obj release]
After all that explains the question, why do I also have to declare obj = nil? Calling [obj release] also seems to kill the pointer. I thought that [obj release] would free the memory that it points to and also set obj to nil all in one shot, but it seems to also kill the pointer because my application crashes when it tries to reference obj after [ obj release];
Does this question make sense? Does this just explain that [obj release] does ALL cleanup, including killing a pointer, and I need to know about it?
If I set the hold property for the SomeObject pointer, will the pointer remain after release?
Thanks in advance!
source share