I understand you need to be careful with autorelease
on iOS. I have a method that is returning an object it alloc
s which is needed by the caller, so in this situation -- as I understand it -- I need to send autorelease
to the object in the callee before it returns.
This is fine, but once control returns to the phone (i.e. after my button click has been processed) it seems that the autorelease pool is released. I suspect this is how it is supposed to be, but I am wondering what is the best practice for this situation.
I have resorted to sending a retain
message from the caller so that the object is not released and then explicitly releasing it in dealloc
.
Is this the best approach?
[[[object alloc] init] autorelease]
, but then the object goes away before you had a chance to use it? – Pseudo