I know that in Objective-c there's a very easy way to declare variables like this:
NSArray* myArray;
@property(retain) NSArray* myArray;
@synthesize myArray;
This way you can use self.myArray as both the setter and getter while retaining the variable. However this will also allow you to do one more thing, which is avoiding yourself using dealloc. As far as I understand, this two lines are the same:
self.myArray = nil;
[myArray release];
My question is, which one is the preferred way? Is there any cases where one of them will work and the other one won't?
EDIT: Sorry, I meant release, not dealloc...
You should never call dealloc yourself (except under very unorthodox circumstances).
Instead of dealloc, you should call [myArray release]
and let the released process take care of this for you.
Have a look here for way more info than you'd probably like on a dealloc method as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With