Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

wli061

macrumors newbie
Original poster
Oct 13, 2008
4
0
Hi Guys,
I am trying to read in a file to a NSString and then creat a NSMutableArray to store the contents divided by "\n". However, after release the array, it looks like the memory still not released. The memory was increasing to 20MB after alloc the array and was still occupied after releasing the array. The memory of NSString can be released no problem. No memory leaks.
Any help will be appreciated.
HTML:
/////////////////////
	//read in test.txt
	NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"test.txt"];
	NSError *error;
	
	NSString *testtest = [[NSString alloc] initWithContentsOfFile:defaultDBPath encoding:NSASCIIStringEncoding error:&error];
	NSMutableArray *Rna = [[NSMutableArray alloc] initWithArray: [testtest componentsSeparatedByString:@"\n"]];
	[testtest release];
	/////////////////////
	//remove all temp arrays
	[Rna removeAllObjects];
	[Rna release];
 

SqueegyX

macrumors regular
Mar 24, 2008
108
1
I'm not sure why you are leaking, but you shouldn't need to remove all objects before you release. When an NSArray is dealloc'd, it releases all of the objects in contains automatically.
 

wli061

macrumors newbie
Original poster
Oct 13, 2008
4
0
Hi SqueegyX, there was no leaks. I tried both autoreleased and released arrays. Looks like they were still occupied the memory after release. Any ideas? I wonder this is a bug on iphone simulator and will try the program on device later.
 

detz

macrumors 65816
Jun 29, 2007
1,051
0
Is it because garbage collection? That memory is set to be released but the GC has not actually released it yet....
 

wli061

macrumors newbie
Original poster
Oct 13, 2008
4
0
It has to be managed memory on iphone. I tried on device and simulator. The autoreleased arrays still took the memory. Is there a way to find out when the autoreleasing happens? Thanks guys.
 

wli061

macrumors newbie
Original poster
Oct 13, 2008
4
0
I have tried on device. It was same result. The reason should be that the autorelease array was not released yet. I even tried aurorelease pool, but no luck. Here are more codes:
1. In app Delegate, I initial a MyViewController.
HTML:
- (void)applicationDidFinishLaunching:(UIApplication *)application {	
	
	// Override point for customization after app launch	
    MyViewController *aViewController = [[MyViewController alloc] initWithNibName:@"ControllerView" bundle:[NSBundle mainBundle]];
	self.myViewController = aViewController;
	[aViewController release];
	UIView *controllersView = [myViewController view];
	[window addSubview:controllersView];
	[window makeKeyAndVisible];
}
- (void)dealloc {
	[myViewController release];
	[window release];
	[super dealloc];
}
2. In MyViewController, I have a function linked to a button.
HTML:
- (IBAction)RnaRns:(id)sender
{
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"rna.crs"];
	NSError *error;
	NSString *testtest = [[NSString alloc] initWithContentsOfFile:defaultDBPath encoding:NSASCIIStringEncoding error:&error];
	NSArray *Rnaarray = [[testtest componentsSeparatedByString:@"\n"] autorelease];
	[testtest release];
}
I wondered the Rnaarray could be only released when the MyViewController was released. I did try put - (IBAction)RnaRns:(id)sende in an object, then initial it in MyViewController and use the function . Then released the object. However, the Rnaarray was still not released. So the real question is how we make sure the autorelease is released and when. Autoreleasepool is not working for this case as well. I cannot afford losing these memory on iphone. Thanks.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.