Re: Memory Leak with NSMutable String
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.