1292 Views 2 Replies Latest reply: Jan 25, 2011 6:16 PM by Den B.
Den B. wrote:
Is my guess correct that when I call \[NSNumber numberWithUnsignedInt:nValue\] the resulting object has an autorelease flag, right?
Yes. The absence of the words "alloc", "new", or "copy" in the method name tell you that you don't own the returned object, and aren't responsible for releasing it; i.e. it's probably been autoreleased, but in any case you can't expect it to persist beyond the current event cycle. Be sure to read [Memory Management Rules|http://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Mem oryMgmt/Articles/mmRules.html#//apple_ref/doc/uid/20000994-BAJHFBGH] in the +Memory Management Programming Guide+ for more general details.
If so, is it safe to call it for a timer that may fire way after the autorelease pool was cleared?
In the case of [scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:|http://develo per.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSTim erClass/Reference/NSTimer.html#//appleref/occ/clm/NSTimer/scheduledTimerWithTimeInterval:target:selector:userInfo:repe ats:], yes, because the doc explicitly says so:
The user info for the timer. The object you specify is retained by the timer and released when the timer is invalidated. This parameter may be nil.