• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Newbie Memory Questions on a Code Fragment
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie Memory Questions on a Code Fragment


  • Subject: Re: Newbie Memory Questions on a Code Fragment
  • From: Kenneth Bruno II <email@hidden>
  • Date: Wed, 21 Jan 2009 10:42:49 -0500

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 (email@hidden)

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:
This email sent to email@hidden


References: 
 >Newbie Memory Questions on a Code Fragment (From: James Cicenia <email@hidden>)
 >Re: Newbie Memory Questions on a Code Fragment (From: Kenneth Bruno II <email@hidden>)
 >Re: Newbie Memory Questions on a Code Fragment (From: James Cicenia <email@hidden>)

  • Prev by Date: Re: Switching NSDocument based application to tabbed views interface
  • Next by Date: Re: Limiting NSTextField to numbers?
  • Previous by thread: Re: Newbie Memory Questions on a Code Fragment
  • Next by thread: Re: Newbie Memory Questions on a Code Fragment
  • Index(es):
    • Date
    • Thread