NSAutoreleasePool question
NSAutoreleasePool question
- Subject: NSAutoreleasePool question
- From: Brant Sears <email@hidden>
- Date: Wed, 17 Sep 2003 14:32:55 -0700
Hi. I have a multithreaded app (that I inherited) which has two threads that
are setup like this:
-(void)myThreadStartsHere:(id)context
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
FuntionThatDoesNotReturnUntilAppIsQuitting();
[pool release];
}
So, it occured to me that this is the reason our memory usage is going
through the roof. OK, so I need to make my app periodically release and then
recreate the NSAutoreleasePool.
I was looking at the NSAutoreleasePool documentation where it says:
"An autorelease pool should always be released in the same context
(invocation of a method or function, or body of a loop) that it was
created."
Since the code that is getting called is somewhat complicated and goes
through several straight C functions, I was thinking of making the
NSAutoreleasePool a member variable of the class. Then I was thinking of
adding a method that would "reset" the autorelease pool:
-(void)resetAutoreleasePool
{
[mAutoreleasePool release];
mAutoreleasePool = [[NSAutoreleasePool alloc] init];
}
Then, I could even setup a C style wrapper funtion and call it periodically
throughout the existing code.
Based on my reading of Apple's documentation, I'm wondering now if this will
lead to trouble. I've already implemented it and it seems to work OK, but
I'm having some related issues and I'm not sure if this is a problem.
Thanks for any help.
Brant Sears
_______________________________________________
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.