Re: I'm leaking memory
Re: I'm leaking memory
- Subject: Re: I'm leaking memory
- From: Shawn Erickson <email@hidden>
- Date: Fri, 11 Feb 2005 11:45:11 -0800
On Feb 11, 2005, at 11:25 AM, Brian O'Brien wrote:
I think the problem is here:
NSMutableArray *acceptAETs = [NSMutableArray arrayWithCapacity:2];
[acceptAETs addObject: [NSString stringWithUTF8String:"ABC"]];
[acceptAETs addObject: [NSString stringWithUTF8String:"DEF"]];
But I don't see what I'm doing wrong.
The message it telling that you don't have a auto release pool in place
so you need to find the code that is generating those messages (if it
isn't obvious) using a break point as suggested and then insure that an
auto release pool is in place. So nothing is wrong with the above code
except that no pool happens to exist when you are trying to execute the
above (likely you have this happening in a secondary thread).
Review the following documentation at the top of the class docs [1] to
understand when you may have to manage your own auto release pools.
"
Each thread maintains its own stack of NSAutoreleasePool objects. As
new pools are created, they get added to the top of the stack. When
pools are deallocated, they are removed from the stack. Autoreleased
objects are placed into the top autorelease pool for the current
thread. When a thread terminates, it automatically releases all of the
autorelease pools associated with itself.
Cocoa expects there to be an autorelease pool always available. If a
pool is not available, objects do not get released and you leak memory.
NSAutoreleasePools are automatically created and destroyed in the main
thread of applications based on the Application Kit, so your code
normally does not have to deal with them. The Application Kit creates a
pool at the beginning of the event loop and releases it at the end,
thereby periodically releasing any autoreleased objects generated while
processing events.
If you are making Cocoa calls outside of the Application Kit’s main
thread, however, you need to create your own autorelease pool. This is
the case if you are a Foundation-only application or if you detach a
thread. If your application or thread is long-lived and potentially
generates a lot of autoreleased objects, you should periodically
destroy and create autorelease pools (like the Application Kit does on
the main thread); otherwise, autoreleased objects accumulate and your
memory footprint grows. If your detached thread does not make Cocoa
calls, you do not need to create an autorelease pool.
"
Also if you haven't already make sure to fully read and understand the
following since it will make your life easier and likely your code
cleaner (note it has a section on autorelease pools)...
<http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/
index.html>
-Shawn
<http://developer.apple.com/documentation/Cocoa/Reference/Foundation/
ObjC_classic/Classes/NSAutoreleasePool.html>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden