• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSKeyedUnarchiver unarchiveObjectWithFile - memory not being freed but no leaks?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSKeyedUnarchiver unarchiveObjectWithFile - memory not being freed but no leaks?


  • Subject: NSKeyedUnarchiver unarchiveObjectWithFile - memory not being freed but no leaks?
  • From: nick briggs <email@hidden>
  • Date: Mon, 2 Oct 2006 15:31:49 +0100

Hello All

Our app uses large data files which we are reading from disk with NSKeyedUnarchiver unarchiveObjectWithFile. the root object being a mutable array of mutable dictionaries

We're having a memory problem and wrote a simple test rig, listed below to figure out whats going on.

When we load our test data using the fillMemoryWithBuffer, our memory usage, as seen in 'top', increases from 2.7m to 426m, this is expected

When we release the array, expecting the memory to be freed, its not, well to be exact it decreases by 2m.

So we run the app again with MallocStackLogging on, and then run 'leaks', none are reported.

Now if we use the fillMemoryWithData function, the memory is allocated and released exactly as expected.

So what gives, we thought we had a pretty good understanding of objc memory patterns, but this is really confusing us.

Any insight into what's going on here will be greatly appreciated.

Cheers

Nick



------------------
//test rig


- (id)init { if(self = [super init]) { array = [[NSMutableArray alloc]init]; } return self; }

// memory not freed
- (void)fillMemoryWithBuffer:sender
{
NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setAllowsMultipleSelection:TRUE];
if([panel runModal] == NSOKButton)
{
unsigned i, c = [[panel filenames]count];
for(i=0; i<c; i++)
{
NSArray *data = [NSKeyedUnarchiver unarchiveObjectWithFile:[[panel filenames]objectAtIndex:i]];
[array addObject:data];

}
}
}


// memory freed
- (void)fillMemoryWithData:sender
{
NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setAllowsMultipleSelection:TRUE];
if([panel runModal] == NSOKButton)
{
unsigned i, c = [[panel filenames]count];
for(i=0; i<c; i++)
{
NSData *data = [NSData dataWithContentsOfFile:[[panel filenames] objectAtIndex:i]];
[array addObject:data];
}
}
}


- (void)releaseMemory:sender
{
	[array release];
}


@end



------------------


// how we create data files

	_complexBuffer		= [[NSMutableArray alloc]init];	

	do{
		....

NSNumber *fft = [NSNumber numberWithFloat:fft];
NSData *data = [NSData dataWithBytes:buffer length:abl.mBuffers [0].mDataByteSize];
NSNumber *c = [NSNumber numberWithInt:count];
NSNumber *size = [NSNumber numberWithInt:abl.mBuffers [0].mDataByteSize];
NSNumber *db = [NSNumber numberWithFloat:average_power];
NSNumber *max = [NSNumber numberWithFloat:mx];
NSNumber *min = [NSNumber numberWithFloat:mi];

NSMutableDictionary *complx = [NSMutableDictionary dictionaryWithObjectsAndKeys:
fft, kBufferFFT,
db, kBufferDB,
data, kBufferFrame,
c, kBufferCount,
size, kBufferSize,
max, kBufferMax,
min, kBufferMin,
nil];

[_complexBuffer addObject:complx];


}
while(...);	

[NSKeyedArchiver archiveRootObject:_complexBuffer toFile:_complexPath];




------------------



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: NSBorderlessWindowMask - shadows not working correctly
  • Next by Date: Re: Cocoa-dev Digest, Vol 3, Issue 1203
  • Previous by thread: Re: NSBorderlessWindowMask - shadows not working correctly
  • Next by thread: Re: Cocoa-dev Digest, Vol 3, Issue 1203
  • Index(es):
    • Date
    • Thread