Re: Never ending lack of memory
Re: Never ending lack of memory
- Subject: Re: Never ending lack of memory
- From: Lorenzo Puleo <email@hidden>
- Date: Sat, 08 Mar 2003 20:50:54 +0100
Hi,
thank you for helping me.
I know that if you create a NSString with some "init" method + "alloc", then
you have to release the NSString.
But if you use other methods you don't need to release the string.
The same is for NSArray, and other classes.
Do I know wrong?
Also, just to understand if the problem comes from the method recursion
(which requires memory any time), and not from the variables memory,
I tried to do only
- (BOOL)ScanSingleFolder:(NSString*)sourceDir
{
[self ScanSingleFolder:subItem];
return YES;
}
And after 508 recursions my Application crashed. Why?
May be this crash log line (the last one)
could help you to understand better the problem.
#508 0x0001a048 in -[MyMainClass ScanSingleFolder2:] (MyMainClass.m6760)
Thanks.
--
Lorenzo Puleo
mailto:email@hidden
>
From: email@hidden
>
Date: Sat, 8 Mar 2003 20:22:58 +0100
>
To: Lorenzo Puleo <email@hidden>
>
Cc: email@hidden
>
Subject: Re: Never ending lack of memory
>
>
>
On samedi, mars 8, 2003, at 07:53 PM, 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?
>
>
>
>
>
> - (BOOL)ScanSingleFolder:(NSString*)sourceDir
>
> {
>
> int i;
>
> NSMutableString *subItem = [NSMutableString string];
>
> BOOL isDir;
>
> NSArray *dirContent = [manager
>
> directoryContentsAtPath:sourceDir];
>
>
>
> for(i = 0; i < [dirContent count]; i++){
>
> if(isCopying == NO) break;
>
> [subItem setString:[sourceDir
>
> stringByAppendingPathComponent:[dirContent objectAtIndex:i]]];
>
> [manager fileExistsAtPath:subItem isDirectory:&isDir];
>
> if(isDir) [self ScanSingleFolder:subItem];
>
> }
>
> return YES;
>
> }
>
>
>
> Thank you for your (hopefully) help.
>
>
1) Why don't you use the BSD routines or the FSRef ones dedicated to
>
scanning directories?
>
>
2) Since you're not releasing any string before the end of the scan,
>
it's not very surprising that the memory is growing a lot.
>
>
To give you an idea of the amount of data not released before the end
>
of the scan, I put a NR on the problematic lines:
>
>
- (BOOL)ScanSingleFolder:(NSString*)sourceDir
>
{
>
int i;
>
NR NSMutableString *subItem = [NSMutableString string];
>
BOOL isDir;
>
NR NSArray *dirContent = [manager
>
directoryContentsAtPath:sourceDir];
>
>
for(i = 0; i < [dirContent count]; i++){
>
if(isCopying == NO) break;
>
NR [subItem setString:[sourceDir
>
stringByAppendingPathComponent:[dirContent objectAtIndex:i]]];
>
[manager fileExistsAtPath:subItem isDirectory:&isDir];
>
if(isDir) [self ScanSingleFolder:subItem];
>
}
>
return YES;
>
}
>
>
Maybe this can be avoided using this kind of folder scanning:
>
>
- (BOOL)ScanSingleFolder:(NSString*)sourceDir
>
{
>
NSDirectoryEnumerator * tEnumerator;
>
NSString * subItem;
>
>
tEnumerator= [manager enumeratorAtPath: sourceDir];
>
>
while ((subItem =[tEnumerator nextObject])!=nil)
>
{
>
...
>
}
>
}
_______________________________________________
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.