|
From: | ramana rao |
Subject: | Problem with NSAutoreleasePool in GNUstep |
Date: | Mon, 3 Dec 2001 17:30:24 +0530 |
JP,
It seeme there is a problem with GNUstep
NSAutorelease pools, unless I am very much mistaken
I wrote a simple program like follows,
***********************************
Check Program memory at
Stage1
NSAutoreleasePool * pool =
[[NSAutoreleasePool alloc] init];
Allocate some memory, say by initializing a
huge array theArray
Check Program memory at
Stage2
release
theArray
Check Program memory at
Stage3
[pool release];
Check Program memory at
Stage4
***********************************
I am expecting the Program memory at Stage1 and Stage4 to be same,
and it is so in OpenStep, but not so in
GNUstep. In GNUstep the memory allocated in within
Autorelease pool block is not released.
Interestingly (in GNUstep) if the above code portion if I repeat,
(say by keeping a loop) the later iterations are not taking new memory.
Previously allocated memory is being used
This a serious problem, with WarmStartServer some time 1 GB is used up and
that goes unreleased
Any idea on this
thanks
Ramana Rao
The Sample code I am giving below
#import <Foundation/Foundation.h>
#import "OIProcessStatistics.h" int main (int argc, const char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSString *str; int i,j; // insert your code here NSLog(@"processStatistics"); file://str = [OIProcessStatistics getCurrentProcessMemoryUsage]; NSLog(@"Memory Usage = %@",[OIProcessStatistics getCurrentProcessMemoryUsage]); {
NSAutoreleasePool * poolInner = [[NSAutoreleasePool alloc] init]; int i;
NSMutableArray *theArr = [ [NSMutableArray alloc] init]; NSLog(@"Memory Usage before allocation = %@",[OIProcessStatistics getCurrentProcessMemoryUsage]); for(i = 0; i< 100000; i++){ [theArr addObject:[NSString stringWithFormat:@"Hellllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo %d",i]]; } NSLog(@"Memory Usage after allocation =
%@",[OIProcessStatistics
getCurrentProcessMemoryUsage]);
[theArr removeAllObjects]; NSLog(@"Memory Usage after removal =
%@",[OIProcessStatistics getCurrentProcessMemoryUsage]);
[theArr
release];
[poolInner release]; NSLog(@"Memory Usage after autorlelease pool =
%@",[OIProcessStatistics
getCurrentProcessMemoryUsage]);
} [pool release]; exit(0); // insure the process exit status is 0 } The supplementary class
OIProcessStatistics.m
/* OIProcessStatistics.m created by Administrator on Thu 25-Oct-2001
*/
#import "OIProcessStatistics.h"
#include <unistd.h> #include <stdlib.h> @implementation OIProcessStatistics + (NSString *)getCurrentProcessMemoryUsage { char buffer[1000]; int i; NSString *str; NSMutableArray *arr; file://NSLog(@"pID = %d",getpid()); sprintf(buffer,"echo q | prstat -p %d > /OITempFile.txt",getpid()); system(buffer); file://NSLog(@"Str = %@",str); arr = [str componentsSeparatedByString:@" "]; file://NSLog(@"arr _One_ = %@",arr); for(i = 0; i <[arr count];i++){ if( [ [arr objectAtIndex:i] length] == 0){ [arr removeObjectAtIndex:i]; --i;} } file://NSLog(@"arr Two = %@",arr); return [arr objectAtIndex:13]; } @end OIProcessStatistics.h
/* OIProcessStatistics.h created by Administrator on Thu 25-Oct-2001
*/
#import <Foundation/Foundation.h>
@interface OIProcessStatistics : NSObject
{ }
+ (NSString *)getCurrentProcessMemoryUsage; @end |
[Prev in Thread] | Current Thread | [Next in Thread] |