• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Big grinding memory leak?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Big grinding memory leak?
      • From: Martin Häcker <email@hidden>
    • Re: Big grinding memory leak?
      • From: David Remahl <email@hidden>
References: 
 >Big grinding memory leak? (From: Martin Häcker <email@hidden>)

  • Prev by Date: Big grinding memory leak?
  • Next by Date: Re: Big grinding memory leak?
  • Previous by thread: Big grinding memory leak?
  • Next by thread: Re: Big grinding memory leak?
  • Index(es):
    • Date
    • Thread