When memory is actually freeded?
- by zhyk
Hello all.
I'm trying to understand memory management stuff in Objective-C.
If I see the memory usage listed by Activity Monitor, it looks like memory is not being freed (I mean column rsize). But in "Object Allocations" everything looks fine.
Here is my simple code:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSInteger i, k=10000;
while (k>0) {
NSMutableArray *array = [[NSMutableArray alloc]init];
for (i=0;i<1000*k; i++) {
NSString *srtring = [[NSString alloc] initWithString:@"string...."];
[array addObject:srtring];
[srtring release];
srtring = nil;
}
[array release];
array = nil;
k-=500;
}
[NSThread sleepForTimeInterval:5];
[pool release];
return 0;
}
As for retain and release it's cool, everything is balanced.
But rsize decreases only after quitting from this little program.
Is it possible to "clean" memory somehow before quitting?