Garbage Collector destroys objects from Interface Builder
if i create an instance of my object in the interface builder, it gets destroyed by the garbage collector immediately after loading. What is a clean way to counter this? I figured out that i can do a [self retain] in the constructor or create an outlet in the window controller. I just think there must be a better official way to开发者_开发技巧 do this? Thanks, Chaosbit
Orphaned objects are generally not a good idea except in special cases, so it's normal that every object have has some other parent object that keeps a reference to it (and retains it).
The best way to achieve this reate an outlet on your window controller (or somewhere else appropriate) and ensure it has the retain attribute set on the property.
(on a sidenote, your object isn't being Garbage Collected, as there is no such thing on Cocoa Touch. It's being autoreleased, which is a different concept)
精彩评论