Re: Why does this leak memory?
Re: Why does this leak memory?
- Subject: Re: Why does this leak memory?
- From: Jamie Curmi <email@hidden>
- Date: Sun, 19 Jan 2003 08:32:36 +1100
Hi All,
I should point out, every time this is called, more leaks occur. It
isn't just the first call of [NSImage imageNamed:@"Connected"] that
leaks (I realise that gets cached). It appears that every call of
copy, followed by the release, ends up with more memory leaked.
MallocDebug shows the leak - and it increases with each call.
Similarly "top" shows the vsize increasing with each call.
Am I missing something here?
Jamie
On Sunday, January 19, 2003, at 03:50 AM, j o a r wrote:
*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.