When memory is actually freeded?
Posted
by zhyk
on Stack Overflow
See other posts from Stack Overflow
or by zhyk
Published on 2010-04-27T20:06:20Z
Indexed on
2010/04/27
20:13 UTC
Read the original article
Hit count: 279
objective-c
|memory-management
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?
© Stack Overflow or respective owner