سؤال

These are classes and they declares pointers... to objects right? You send methods to them like objects. NSNumber * myNumber = [NSNumber numberWithInteger: x];

So why are they not released like so: [myNumber release];

Thanks!

هل كانت مفيدة؟

المحلول

By convention, class method initializers like the one you've shown create autoreleased instances, so you don't need to call release unless you retain them somehow. However, the instance method initializers - like initWithInteger: in your case - return retained instances. Those you would need to release yourself.

نصائح أخرى

There is a rule you should remember about memory management "NARC": When you use New Alloc Retain Copy you should release or autorelease object, otherwise you shouldn't.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top