Re: Big grinding memory leak?
Re: Big grinding memory leak?
- Subject: Re: Big grinding memory leak?
- From: David Remahl <email@hidden>
- Date: Sun, 27 Apr 2003 23:07:52 +0200
Martin,
You either need more than a single autorelease pool level, or you need
to periodically empty the autorelease pool and recreate it. Even though
you don't use autorelease directly, one of the methods you call may.
One of these, in other words:
(1)
void main(int argc, const char **argv )
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSEnumerator *enumerator = [[NSFileManager defaultManager]
enumeratorAtPath:basePath];
int counter = 1;
id currObj;
while( currObj = [enumerator nextObject] )
{
// do cool stuff with currObj
if( currObj++ % 10 == 0 )
{
[pool release];
pool = [[NSAutoreleasePool alloc] init];
}
}
[pool release];
return 0;
}
(2)
void main(int argc, const char **argv )
{
NSAutoreleasePool *poolOne = [[NSAutoreleasePool alloc] init];
NSEnumerator *enumerator = [[NSFileManager defaultManager]
enumeratorAtPath:basePath];
int counter = 1;
id currObj;
while( currObj = [enumerator nextObject] )
{
NSAutoreleasePool *poolTwo = [[NSAutoreleasePool alloc] init];
// do cool stuff with currObj
[poolTwo release];
}
[poolOne release];
return 0;
}
/ Regards, David
On Sunday, April 27, 2003, at 10:44 PM, Martin Hdcker wrote:
Hi there,
today I just tried a little helper app that enumerates over all the
files of the current directory and tells me which of the pictures
within are below 1024*768.
Well, that seems to work, but I have the big problem that every time I
use this my memory usage absolutely skyrockets and has already brought
down my system once (partly because the stupid implementation of
NSUserDefaults thinks it's fun to throw away all its preferences if
the disk is too full to save a new copy).
Well... as far as I understands this there should be no immediate
problem with this implementation as all the objects in it will either
be very small (the autoreleased strings) or get a release immediately
meaning that they should be destroyed.
Right?
--- snip ---
#import <Cocoa/Cocoa.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
id basePath = [[NSFileManager defaultManager]
currentDirectoryPath];
id direcotryIterator = [[NSFileManager defaultManager]
enumeratorAtPath:basePath];
id currentFile;
NSSize size;
while (currentFile = [direcotryIterator nextObject]) {
size = NSMakeSize(0, 0);
id currentImage = [[NSImage alloc]
initWithContentsOfFile:currentFile];
if (currentImage) { // may be nill if currentFile is not an
image
size = [currentImage size];
if (size.width < 1024 || size.height < 768) {
// fixme: something better?
printf("%s\n", [currentFile cString]);
}
[currentImage release];
}
}
[pool release];
return 0;
}
--- snap ---
I must clearly be overlooking something pretty simple here, but I
can't see it.
Thanks in advance for any help,
cu Martin
--
dont.wanna.tell
[ot]coder - hehe
_______________________________________________
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.