Sunday, October 11, 2009

iPhone dev Stupidity 46: retain vs asign - who's the owner?

Don't use retain just because it's convenient.

If a child holds a reference to it's parent, it's not a retain - from the life time perspective, when the parent get released, the child will be released. It's an assign.

If the child retain the parent: 

parent new 0 -> 1
child -> parent 1 -> 2
parent release 2 -> 1

The parent will have no chance to get released with the extra retain.

No comments: