ios - Autoreleasepool drained only at end of app? -
in ios primary autorelease pool wraps around uiapplicationmain. if don't manually set other autorelease pools inside app, mean whenever release object in app autorelease, not released until uiapplicationmain done, pool drained, , app terminates?
that's seems case , if seems bad idea use autorelease. objects, if created temporary reason, stick around until app ends, waisting lot of memory.
for example, many factory methods think use autorelease. created using factory method released when app finishes?
not @ all!
uiapplicationmain creates main run loop app. can treat infinite loop handles messages in current queue , continues next iteration.
autorelease pool drains autoreleased objects @ end of every run loop iteration. means, app handles touch event on button , reloads table view in single iteration of run loop. autoreleased objects created in mean time drained after iteration completes.
the run loop still continue run till application runs , continue handle further iterations.
however, if create separate thread in app have own run loop , consequentially responsibility create autorelease pool new thread spawn.
Comments
Post a Comment