Monte Hurd
Monte Hurd

Reputation: 4437

Can I release a no longer needed property of an instance of an object without worrying that dealloc will later "over-release" it?

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?

Upvotes: 1

Views: 96

Answers (1)

Rob Napier
Rob Napier

Reputation: 299275

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.

Upvotes: 6

Related Questions