Re: Never ending lack of memory
Re: Never ending lack of memory
- Subject: Re: Never ending lack of memory
- From: Dietrich Epp <email@hidden>
- Date: Mon, 10 Mar 2003 02:43:40 -0800
On Saturday, Mar 8, 2003, at 10:53 US/Pacific, Lorenzo Puleo wrote:
I call the following recursive routine
[self ScanSingleFolder:@"/"]; (see below)
and the Terminal top command reports and increasing RSize of 80, 90,...
400...MB. My application grows 4MB each second. I get I lot of pageins
and
pageouts, and up above, even if I stop the task, I have to wait long
time to
free up the CPU again, and last, this amount of RSize never decreases.
Where did I do wrong?
Here's how you take care of autorelease'd things in loops. Don't worry
about switching stringBy-- to alloc/init because if your code leaks
like a seive [as it does] you don't want to patch leaks one by one if
you don't have do [as you don't]. Also, autorelease is safer.
- (BOOL)ScanSingleFolder:(NSString*)sourceDir
{
int i;
NSMutableString *subItem = [NSMutableString string];
BOOL isDir;
NSArray *dirContent = [manager
directoryContentsAtPath:sourceDir];
NSAutoReleasePool* aPool;
for(i = 0; i < [dirContent count]; i++){
if(isCopying == NO) break;
aPool = [[NSAutoReleasePool alloc] init];
[subItem setString:[sourceDir
stringByAppendingPathComponent:[dirContent objectAtIndex:i]]];
[manager fileExistsAtPath:subItem isDirectory:&isDir];
[aPool release];
if(isDir) [self ScanSingleFolder2:subItem];
}
return YES;
}
_______________________________________________
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.