Re: Memory leak.
Re: Memory leak.
- Subject: Re: Memory leak.
- From: Clark Cox <email@hidden>
- Date: Sat, 12 Feb 2005 12:02:02 -0500
On Sat, 12 Feb 2005 11:49:02 -0500, Coleman Nitroy <email@hidden> wrote:
> I cannot figure out where this is leaking. I took out everything but
> just the for loop statements and the ints for counters. When I run
> this, I have a NSLog saying this code has completed execution. This
> loop gets called many times, anywhere from once to a few thousand
> times, and if I run it twice or something, no problem, but if I have it
> run many many times, it starts to slow down exponentially and with each
> pass memory usage goes up up up.
>
> - (id) initWithPlanes: (NSArray *) planes withProperties: (NSArray *)
> properties
> {
> [super init];
> int i, j, k;
>
> for ( i = 0; i < [properties count] - 3; i++ ) {
> for ( j = 0; j < [properties count] - 2; j++ ) {
> for ( k = 0; k < [properties count] - 1; k++ ) {
>
> // some stuff that I have commented out.
>
> }
> }
> }
>
> return self;
> }
What is likely happening is that your code is allocating some objects
that are autoreleased. These objects won't go away until the current
autorelease pool is deallocated, which usually happens when your code
returns to the main event loop. You can probably fix this by using
your own, local, autorelease pool. Try something like:
- (id) initWithPlanes: (NSArray *) planes withProperties: (NSArray *)
properties
{
[super init];
int i, j, k;
for ( i = 0; i < [properties count] - 3; i++ ) {
for ( j = 0; j < [properties count] - 2; j++ ) {
for ( k = 0; k < [properties count] - 1; k++ ) {
NSAutoreleasePool *localPool = [[NSAutoreleasePool alloc] init];
// some stuff that I have commented out.
[localPool release];
}
}
}
return self;
}
You can experiment with which level of the loop gives the best result.
That is, moving the pool into one of the outer loops might give your
better speed at the cost of more memory.
--
Clark S. Cox III
email@hidden
http://www.livejournal.com/users/clarkcox3/
http://homepage.mac.com/clarkcox3/
_______________________________________________
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
References: | |
| >Memory leak. (From: Coleman Nitroy <email@hidden>) |