NSKeyedUnarchiver unarchiveObjectWithFile - memory not being freed but no leaks?

  • 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];

    ------------------
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today