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: Sun, 09 Mar 2003 12:15:43 +0100
Ok,
I understand, the memory is not released.
So I try to *alloc* and *init* NSString and NSArray and release them at the
end of each recursion by myself (see below).
Itried this but it didn't work. When NSLog appears coming out from the dir,
say "/Applications", the memory is still the same, and it is still
increasing. Instead it should be like the moment I launched this method the
first time. Sorry, it doesn't work.
I miss some important step of the memory theory.
- (BOOL)ScanSingleFolder:(NSString*)sourceDir
{
int i;
NSMutableString *subItem = [[NSMutableString alloc] init];
BOOL isDir;
NSArray *dirContent = [[NSArray alloc] initWithArray:
[manager directoryContentsAtPath:sourceDir]];
for(i = 0; i < [dirContent count]; i++){
[subItem setString:[sourceDir
stringByAppendingPathComponent:[dirContent objectAtIndex:i]]];
[manager fileExistsAtPath:subItem isDirectory:&isDir];
if(isDir){
[self ScanSingleFolder:subItem];
if([sourceDir isEqualToString:@"/"]
NSLog(@"Came out from: %@", subItem);
}
}
[dirContent release];
[subItem release];
return YES;
}
Ans last:
why does the following call, crash after 508 recursion?
- (BOOL)ScanSingleFolder:(NSString*)sourceDir
{
[self ScanSingleFolder:@"/"];
return YES;
}
There is no memory usage, no variables, no strings, no array.
Does this mean that, even in case I populate here the call with variables
(like the previous full case), the max number of recursions is 508?
Mistery of the memory...
--
Lorenzo Puleo
mailto:email@hidden
>
From: email@hidden
>
Date: Sun, 9 Mar 2003 00:28:25 +0100
>
To: Lorenzo Puleo <email@hidden>
>
Subject: Re: Never ending lack of memory
>
>
>
On samedi, mars 8, 2003, at 11:27 PM, Lorenzo Puleo wrote:
>
>
> What you suggested is exactly what I did firts. And it makes the memory
>
> increase to infinite.
>
> So I tried to use a NSMutable string...
>
> Anyway, I use this, but please, why does the memory increase forever?
>
>
>
> I also put an NSLog just after the call to the recursion (see below).
>
> I expected that just coming out the folder (e.g.) /Application, the
>
> RSize of
>
> myApplication should decrease in the Terminal. But this never happens.
>
> Instead it increases any time. It doesn't decrease neither after the
>
> routine
>
> ends. Why?
>
>
Because the memory is not released.
>
>
Time for detailed description of the problem of what is happening:
>
>
T-1 The NSAutoreleasePool is created
>
>
T Time ScanSingleFolder: is called
>
>
dirContent = [manager directoryContentsAtPath:sourceDir];
>
>
This allocates the returned array as an autorelease object. It will be
>
released when the autorelease pool is released
>
>
subItem =[sourceDir stringByAppendingPathComponent:[dirContent
>
objectAtIndex:i];
>
>
The subItem is allocated as an autorelease object too.
>
>
[self ScanSingleFolder:subItem]; is called if a subItem describes the
>
path of a folder
>
>
dirContent = [manager directoryContentsAtPath:sourceDir];
>
>
This allocates the returned array as an autorelease object. It will be
>
released when the autorelease pool is released
>
>
subItem =[sourceDir stringByAppendingPathComponent:[dirContent
>
objectAtIndex:i];
>
>
The subItem is allocated as an autorelease object too.
>
>
etc...
>
>
T2 The recursion ends for a leaf. No memory is released, this is the
>
job of the autorelease pool.
>
>
T3 The first call of ScanSingleFolder: ends.
>
>
T4 The main RunLoop now releases the NSAutorelease object which will
>
then call release on every object attached to it (i.e. way more than
>
the number of files on your Hard disks since every file path is in the
>
autorelease pool if the folder to scan is "/").
_______________________________________________
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.