• 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: Memory Leak with NSMutable String
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Memory Leak with NSMutable String


  • Subject: Re: Memory Leak with NSMutable String
  • From: lbland <email@hidden>
  • Date: Mon, 26 Jan 2004 09:59:58 -0500

On Jan 26, 2004, at 9:09 AM, Alexander F. Hartner wrote:

Thanks for your help. Does this mean that the memory used by these NSMutableString will only be released once the NSAutoreleasePool is released.

yes.

Currently the memory usage seems to increase even though I am only using one instance of NSMutableString.

that's where you go wrong. stringWithCapacity returns a new (autoreleased) string for each call. Not a shared string.

Would this problem go away if instead of initialising the NSMutuableString with the initWith method

yes (as long as you release when done with it).

I would rather call init and then release it manually rather then relying on auto release ?

yes. autoreleased stuff is so that you can use a free store with function returns. It's to get around that known issue of free store temps being returned in methods in C++ style codings (in addition to other things...). The same applies to obj-c.

autoreleased stuff globalizes your code and makes it more prone to misuse, so anytime you can get rid of a autorelease object the better off you are.

-lance
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Memory Leak with NSMutable String (From: "Alexander F. Hartner" <email@hidden>)
 >Re: Memory Leak with NSMutable String (From: Peter Maurer <email@hidden>)
 >Re: Memory Leak with NSMutable String (From: "Alexander F. Hartner" <email@hidden>)

  • Prev by Date: NSRect and NSPoint question
  • Next by Date: Re: Disabling Exposé for some windows, some da y =3 F
  • Previous by thread: Re: Memory Leak with NSMutable String
  • Next by thread: Re: Memory Leak with NSMutable String
  • Index(es):
    • Date
    • Thread