On Jan 21, 2009, at 9:07 AM, Kenneth Bruno II wrote:


        NSDateFormatter *aFormatter = [NSDateFormatter new];    
NSArray *listOfMonthNames = [[aFormatter standaloneMonthSymbols] retain];

One small error here, I should have added this line after these two in order to properly release the NSDateFormatter:

    [aFormatter release];

This needs to be done because I created a new NSDateFormatter which has a retain count of 1. Since I don't need it past this point I should release it. It's a small memory leak if I don't but it's a good idea to always properly clean up after yourself. Instead of adding an additional line to release I could have also just changed the first line to this:

    NSDateFormatter *aFormatter = [[NSDateFormatter new] autorelease];

The advantage to using autorelease is that I now don't need to remember to release later and it puts the allocation and cleanup all in one line, producing cleaner code. The disadvantage is that autoreleasing takes up a bit more time and memory than just releasing the object. In this case that's negligible, only worry about it if you are creating and autoreleasing tons of objects in time or memory- critical code.
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to