tags:

views:

58

answers:

1

I have an instance of an object "myObject" that has a few UIImage objects as properties. After I access these properties the first time I really don't need them any more.

Can I do a release on the instance's UIImage properties before the instance itself is released, or will this over-release the UIImage properties later when the "myObject" dealloc releases them also?

+6  A: 

Any time you release an variable that is still in scope, you should immediately set it to nil. This will avoid the problem you're discussing in -dealloc. The best way to achieve this is to always use accessors. If you use accessors, then calling self.foo=nil will take care of everything for you.

Rob Napier
I am using accessors. So I just do "myObject.someImage = nil" to free memory and leave the object's dealloc do the release as usual? If I've got that right it seems easy enough. Thanks!!
Monte
Yep that's the recommended way. The accessor will do nothing if the variable is already nil, and will call release on the object otherwise.
Felixyz