Re: Why is this code leaking memory?
Re: Why is this code leaking memory?
- Subject: Re: Why is this code leaking memory?
- From: Jan Van Boghout <email@hidden>
- Date: Fri, 20 Dec 2002 07:06:51 +0100
Apparently my data and something else is leaking (probably the
imageRep). But that still doesn't solve the problem Why would the code
leak?
Process 672: 7725 nodes malloced
Process 672: 2 leaks
Leak: 0x001aa2a0 size=190
0x00000000 0x00000000 0x00000000 0x6d6f7573
0x00000005 0x00000001 0x40c6d6e1 0x6976bc1f
0x00000001 0x00000001 0x00000000 0x00000000
0x01626c65 0x00010002 0x00000070 0x00000005
0x43f68000 0x440ec000 0xc44b0000 0xc4200000
0x00000aa2 0xaa78eb58 0x00000100 0x0000004b
0x0000ee1f 0x000006f4 0x00000001 0x00000000
0x0000ffff 0x00000000 0x00000000 0x00000000
...
Leak: 0x00086220 size=30 instance of 'NSCFData'
0x0004ebb0 0x00010584 0x00000145 0x00000200
0x00000000 0x000863c0 0xa1b1c1d3
try running the command line tool, `leaks pid' to see if what you are
leaking.
Thanks,
Andrew Pinski
On Thursday, Dec 19, 2002, at 12:32 US/Pacific, Jan Van Boghout wrote:
I'm beginning to suspect that *both* are leaking, which is even more
awkward. (And I tried adding them to a new autoreleasepool, didn't
help)
Interesting. What's being leaked -- the data, or the ImageRep? You
should post what you sent to me to the list; maybe somebody else has
some ideas.
Dan
On Thursday, December 19, 2002, at 12:24 PM, Jan Van Boghout wrote:
imageData = [[NSData alloc]
initWithContentsOfFile:@"/Library/Desktop
Pictures/Aqua Blue.jpg"];
imageRep = [[NSBitmapImageRep alloc] initWithData:imageData];
[imageData release];
[imageRep release];
didn't work either, still leaks. This is not in a loop, it gets
called when I want a new pic and the imageRep of that pic.
Not quite answering your original question, but this may provide
some insight. The "imageRep" object you create is autoreleased,
and
so is the NSData object. Because you did not "alloc" (or copy)
them, they are temporary, autoreleased objects. So your calling
release on it is not really what you want to do, because it should
take care of the releasing for you when you get back to the event
loop.
Could this be something you are running within a loop, so that the
autorelease pool doesn't get a chance to clear itself?
It would be a good idea to either surround your code in a new
autorelease pool, or change your statement to instead explicitly
alloc/init the NSData and the NSBitmapImageRep objects, and then
release them when you are done with them. I can't guarantee that
this will solve the problem, though....
On Thursday, December 19, 2002, at 11:31 AM, Jan Van Boghout
wrote:
Hello everybody,
I have two lines that load an imageRep of an image on the HD, and
they're leaking memory like hell. Any ideas why this is happening?
It
shouldn't, that's the problem.
Code:
imageRep = [NSBitmapImageRep imageRepWithData:[NSData
dataWithContentsOfFile:@"/Library/Desktop Pictures/Aqua
Blue.jpg"]];
[imageRep release];
Say I want to load the Aqua Blue desktop pic. *Every* time this
gets
called my test app's virtual memory usage increases with 3 MB or
more,
I don't even need to load different pics. Any ideas to prevent
this
from happening? Shouldn't the release actually release the
memory? I
also tried creating the data separately and releasing it
separately,
but that doesn't solve the leak either.
All ideas much appreciated,
Jan Van Boghout
_______________________________________________
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.
--
Dan Wood
Karelia Software, LLC
email@hidden
http://www.karelia.com/
Watson for Mac OS X: http://www.karelia.com/watson/
_______________________________________________
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.
--
Dan Wood
Karelia Software, LLC
email@hidden
http://www.karelia.com/
Watson for Mac OS X: http://www.karelia.com/watson/
The information contained in this message or any of its attachments
may be privileged and confidential and intended for the exclusive use
of the addressee(s). Any disclosure, reproduction, distribution or
other dissemination or use of this communication is strictly
prohibited.
_______________________________________________
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.
_______________________________________________
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.
_______________________________________________
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.