Re: Leaks When Running MultiThreaded (Even w/ AutoRelease Pool)
Re: Leaks When Running MultiThreaded (Even w/ AutoRelease Pool)
- Subject: Re: Leaks When Running MultiThreaded (Even w/ AutoRelease Pool)
- From: Shawn Erickson <email@hidden>
- Date: Sat, 4 May 2002 09:05:17 -0700
On Saturday, May 4, 2002, at 08:02 AM, Charles Srstka wrote:
I also had strange memory leaks caused by my worker threads until the
people on this mailing list advised me not to ever access GUI elements
from the worker threads and to use Distributed Objects instead to tell
the main thread to do these things. After doing this, it seems to work
a lot better...
On Saturday, May 4, 2002, at 07:18 AM, Rich Long wrote:
At 8:35 PM -0500 5/3/02, Philip Weaver wrote:
My application behaves *leak-free* when run single-threaded. I've
verified this using OmniObjectMeter. But, when I integrate threading
into this exact same code, all sorts of objects do not get released.
And I am creating an AutoreleasePool for the worker thread and am
even releasing it at the end of the worker thread.
Do you have any pointers for other causes of memory leaks when
threading?
To isolate the problem, I created a test project that loads and
immediately releases a panel from a nib in either the main context or
from a thread. When loaded from the thread (an autorelease pool is in
place), it exhibited the leak:
NSAutoreleaseNoPool(): Object 0x1f0a60 of class NSCalibratedRGBColor
autoreleased with no pool in place - just leaking
If you see this it means you don't have an NSAutoreleasePool in place
when some is trying to call autorelease. Every NSThread maintains a
stack of autorelease pools for you and by default NSThread does NOT
create an autorelease pool for you. In the case of the main thread
NSApplication/etc has created one for you but for all secondary threads
you must create one (either directly or by some AppKit "thingy" that
does it for you).
Please read the online docs about NSAutoreleasePool...
http://developer.apple.com/techpubs/macosx/Cocoa/Reference/Foundation/ObjC_classic/
Classes/NSAutoreleasePool.html
Also using Apple dev site search to search for "autoreleased with no
pool in place - just leaking" should get you an answer as well.
It is also better to do all of your drawing for a single thread, usually
the main thread. You can use multiple thread to do drawing but you just
have to be careful about...
-Shawn
_______________________________________________
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.