Re: Why does this leak memory?
Re: Why does this leak memory?
- Subject: Re: Why does this leak memory?
- From: j o a r <email@hidden>
- Date: Sat, 18 Jan 2003 17:50:23 +0100
*When* does it leak? You create a temporary, autoreleased, object like
this:
[NSImage imageNamed:@"Connected"]
...then you make a copy of that object. Now you have two objects, one
autoreleased and one with a retain count of one. After that you release
the copied object, but the autoreleased object will remain for the
duration of the current event loop. If you sample directly after
releasing the copied object you would notice that you still have one
object around - and this is as it should.
If you create a lot of autoreleased objects in a loop, you might
consider using local autorelease pools. There is plenty of
documentation on that topic, both in the docs from Apple, in the list
archives, and online - notably on stepwise.com.
j o a r
On Saturday, Jan 18, 2003, at 13:59 Europe/Stockholm, Jamie Curmi wrote:
Maybe this is a stupid question. Could someone tell me why the
following code leaks memory (under 10.2.3)?
NSImage * icon = [[NSImage imageNamed:@"Connected"] copy];
[icon release];
Of course, that isn't what my program does. But my program leaks, and
I've simplified it down to that. I thought that the "release" would
cleanup the copy of the icon I've made, but that doesn't seem to be
the case.
_______________________________________________
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.