discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Memory leaks?


From: Nicola Pero
Subject: Re: Memory leaks?
Date: Mon, 5 Sep 2005 14:13:07 +0100 (BST)

Ahm ... it would be a leak if every time you call NSLog, 50 objects get
allocated and never released ... then the program would go on allocating
more and more objects until eventually running out of memory. :-)

But you called it just once.  The objects you see might be internal
'static' data used by the libraries, that are initialized at the first
NSLog call.

Try invoking NSLog again and again ... if the number of objects remains
fixed to 50, then there is no leak and you can happily call as many NSLog
as you want without running out of memory.  Obviously if every NSLog 
invocations creates 50 new objects that are never released, then indeed 
you have found a leak! ;-)

Thanks



> Hi there,
> 
> while testing and playing around with instance counting, I found that a
> simple
> 
>   void main(void)
>   {
>     NSAutoreleasePool *pool = nil;
> 
>     pool = [[NSAutoreleasePool alloc] init];
>     {
>       NSObject *o;
> 
>       o = [[NSObject alloc] init];
>       NSLog(@"--> %@", [o description]);
>       [o release];
>     }
>     [pool release];
> 
>     exit(EXIT_SUCCESS);
>   }
> 
> gives me a total of 50 instances not accounted for:
> 
> ./shared_obj/example: Memory leak detected: NSBundle (2), NSRecursiveLock
> (2), NSUserDefaults (1), GSArrayEnumerator (35), NSLock (1),
> GSArrayEnumeratorReverse (1), GSLazyRecursiveLock (3), NSFileManager (1),
> GSNonretainedObjectValue (4)
> 
> Removing the NSLog(), I get no leak.
> Shouldn't the autorelease pool take care of those instances?
> 
> 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]