iphone - lifetime of [NSMutableDictionary dictionaryWithCapacity:n] -
i thought object returned nsmutabledictionary dictionarywithcapacity:
released when autorelease pool in main.m drained. instead, when assign instance member in -init, find object lasts long -init call.
what managing release of object returned nsmutabledictionary dictionarywithcapacity:
?
to further mystify going on here, find when assign object of custom class created convenience constructor instance member in init, instance still "alive" in (for example) touchbegan: ...
generally speaking, apis 1 return autorelease
d instances.
that mean when autorelease pool drains, object destructed. if don't manage autorelease pool yourself, should destructed when next return message queue (assuming you're on ui thread).
internally, os pushes , pops autorelease pool around each event calls code. so, if have -touchbegan
, there new pool pushed before -touchbegan
gets called, , popped -touchbegan
returns.
if that's not want, you'll have retain
yourself.
Comments
Post a Comment