NSKeyedUnarchiver unarchiveObjectWithFile - memory not being freed but no leaks?
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