I'm an iPhone/Objective-C newbie with an extensive Java background.
I'm learning more about memory management in objective-c and I'm reading Apple's documentation on Memory Management: http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html
In the Object Ownership Policy section, it says that you own any object you create via a method that begins with alloc, new or contains copy. Ownership implies that you need to explicitly release
the object when you are done with it.
So I'm looking at the NSMutableArray documentation: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/Reference/Reference.html
There are two methods that pretty much do the same thing...they both create an array with some initial capacity. One is a class method and the other is an instance method.
+ (id)arrayWithCapacity:(NSUInteger)numItems;
- (id)initWithCapacity:(NSUInteger)numItems;
Now being the lazy Java developer I am, why would I ever choose the instance method over the class method knowing that at some point in time I have to clean up after myself?
I guess I may be missing a fundamental point here...is it simply a matter of determining when the object gets released? autorelease
in the class method vs. release
in the instance method? I suppose that on a platform with very limited resources (iPhone) I should refrain from using the class method and release the object as soon as I'm done with it?
Thanks!