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: Sun, 19 Jan 2003 00:48:25 +0100
On Saturday, Jan 18, 2003, at 23:27 Europe/Stockholm, Jamie Curmi wrote:
It isn't the [NSImage imageNamed:@"Connected"] which is leaking - as
I've replaced that code with just that, and run it many times - no
leaks. But when I make a copy, then release that copy, the leak
occurs.
I made a small test application to try it out (source code below). What
I found when running the copy-release pattern 5000 times was this (as
sampled in top):
RSIZE VSIZE
Before loop: 3 MB 40 MB
After loop: 75 MB 110 MB
After releasing pool: 15 MB 50 MB
But if I repeated the test over and over again, it always returned back
to 15 MB after the loop, like this:
RSIZE VSIZE
Before loop: 15 MB 50 MB
After loop: 75 MB 110 MB
After releasing pool: 15 MB 50 MB
I admit that I find it strange that the app grew from 3 -> 15 MB even
after the autorelease pool was released of the contents collected
during the loop (each copy of the image resulted in 13 items in the
autorelease pool), but since it doesn't continue to bleed memory on
consecutive runs I wonder if it's really a leak or just some sort of
artifact of lazy initialization of stuff somewhere else? This, however,
is as far as I can speculate on this topic - I hope someone else could
give us a better informed opinion.
If I only looped 1000 times, the results were these:
RSIZE VSIZE
Before loop: 3 MB 40 MB
After loop: 17 MB 55 MB
After releasing pool: 5 MB 42 MB
// Source
@interface MyController : NSObject
{
@private
NSImage *myImage;
}
- (IBAction) startLoop:(id) sender;
@end
@implementation MyController
- (void) awakeFromNib
{
myImage = [NSImage imageNamed: @"test.gif"];
}
- (IBAction) startLoop:(id) sender
{
int i = 5000;
while (i--)
{
[[myImage copy] release];
}
}
@end
j o a r
_______________________________________________
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.