Leak in NSImage drawInRect with ColorSync profile?

  • So I've got some code that look like:

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc]
    initWithBitmapDataPlanes:&myRGBData
                                         pixelsWide:myWidth / scale pixelsHigh:myHeight / scale
            bitsPerSample:8 samplesPerPixel:3 + myAlpha
                                           hasAlpha:myAlpha isPlanar:NO
                                         colorSpaceName:NSDeviceRGBColorSpace
                                         bytesPerRow:alignwidth(myWidth)*(3 + myAlpha)
                                        bitsPerPixel:8 * (3 + myAlpha)];
    NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(myWidth /
    scale, myHeight / scale)];
    [image addRepresentation:bitmap];
    if ([myPostProcess nonTrivial]) {
           [bitmap setProperty:NSImageColorSyncProfileData withValue:
    [myPostProcess colorSyncProfile]];
    }
    [bitmap release];
    [image drawInRect:[self bounds] fromRect:NSMakeRect
    (0.0,0.0,myWidth / scale, myHeight / scale)
    operation:NSCompositeSourceOver fraction:1.0];
    [bitmap setProperty:NSImageColorSyncProfileData withValue:NULL];
    [image release];
    [pool release];

    The idea being that, if there is some post-processing color
    correction, we use attach a ColorSync profile to the bitmap and then
    draw it.  Looks great on the screen - slide the "contrast" slider,
    and the image's contrast adjusts perfectly (this is designed to work
    on 10.3.9 so no CoreImage filters, not to mention that this also
    allows me to embed the ColorSync profile when saving the image).  The
    problem is that it appears that if there is a profile attached to the
    bitmap, drawInRect ends up allocating memory that never gets freed.
    ObjectAlloc shows chunks of 3/4 Meg are allocated:

    Event: (#647698) AllocationEvent
    Time Index: 183507447.401161
    Category: GeneralBlock-782336
    Pointer: 0x17e3c000        Size: 782336
    Thread: 0xd03        Extra Data: 0x0
    Backtrace:
    img_data_lock
    CGSImageDataLockWithReference
    0x9471d538
    0x9471bcd0
    CGContextDelegateDrawImage
    CGContextDrawImage
    -[NSBitmapImageRep
    _drawFromRect:toRect:operation:alpha:compositing:flipped:ignoreContext:]
    -[NSImage drawInRect:fromRect:operation:fraction:]
    -[QuiRenderView refreshWithRGBData:]

    I've added the autorelease pool to attempt to make sure that
    everything (the image and bitmap) are freed, but no help - same with
    reseting the bitmap's color sync profile (and from looking at
    ObjectAlloc, it definitely appears that both the image and bitmap are
    released - there's no leaks of them).  There are also smaller
    allocations for ColorWorlds (also not freed):

    Event: (#474509) AllocationEvent
    Time Index: 183507439.623727
    Category: GeneralBlock-24576
    Pointer: 0x17855000        Size: 24576
    Thread: 0xd03        Extra Data: 0x0
    Backtrace:
    CMMMemMgr::New(unsigned long, char const*)
    CMMBase::NewInternal(unsigned long, CMMMemMgr&, char const*)
    CMMTable::CMMTable[unified](unsigned long, CMMMemMgr&, CGFunction*)
    CMMParaCurveTag::MakeLutTable(CMMFloatLutInfo*, CMMMemMgr&,
    CMMLutRangeMapping)
    CMMRGBCurves::MakeLutTable(CMMFloatLutInfo*, CMMMemMgr&, unsigned long)
    ConversionManager::AddMatrixConv(CMMXYZTag* (&) [3], CMMRGBCurves&)
    ConversionManager::MakeConversionSequence(CMMProfileInfoContainer*,
    CMMColorConversionInfo*)
    ConversionManager::MakeColorMatchSequence(CMMProfileInfoContainer*,
    CMMColorConversionInfo*)
    CMMMakeColorMatchConversion(CMMMemMgr&, CMMProfileInfoContainer*,
    CMMColorWorldData*, unsigned long)
    DoNConcatInit
    NCWConcatColorWorld
    0x946c88a8
    0x946d05a0
    0x946c8270
    0x946c80f8
    0x946c8088
    CGColorTransformConvertNeedsCMS
    img_data_lock
    CGSImageDataLockWithReference
    0x9471d538
    0x9471bcd0
    CGContextDelegateDrawImage
    CGContextDrawImage
    -[NSBitmapImageRep
    _drawFromRect:toRect:operation:alpha:compositing:flipped:ignoreContext:]
    -[NSImage drawInRect:fromRect:operation:fraction:]
    -[QuiRenderView refreshWithRGBData:]

    So any idea how to release this memory?  Or is this just a plain old
    bug (and any suggested work arounds)?

    Glenn Andreas                      <gandreas...>
      <http://www.gandreas.com/> wicked fun!
    quadrium | flame : flame fractals & strange attractors : build,
    mutate, evolve, animate
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