It works… it doesn’t crash, and it appears to do what I need.
This could be a design flaw of my application but its the easiest way to do what I need. Basically a view is displayed and controls within the object itself determine when it is removed from the superview (at which point it needs to be released).
At this point its easiest to do [self release], which appears to work.
However, I’m aware of object ownership, and I’m aware that instantiating an object which releases itself is not a good design of object ownership – ie the owner class (the one which instantiates the new object) should be the one which releases it. This would then, however, require me to write delegate methods calling back to the owner class, all just to release the object.
Thoughts please? 🙂
Thanks
Usually, the superview has the retained reference to the child view, and when it gets removed, that reference is released. Why do you need to release it again?
If you do [self release] you are removing ownership of this object from some other piece of code (that holds a retained reference to it). If you do that, that other piece of code will still have a non-nil reference to a piece of garbage memory. It seems to me that this other piece of code should be notified of this situation (and then it might as well issue the release itself).
The pattern you usually see in code samples is