• 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
Thousands of leaked CGContext ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Thousands of leaked CGContext ?


  • Subject: Thousands of leaked CGContext ?
  • From: Eric Matecki <email@hidden>
  • Date: Fri, 17 Apr 2015 11:38:27 +0200

Hi,

(I know this is not 100% Cocoa, but it isn't 100% CoreGraphics either...)

I'm drawing to an NSWindow with CoreGraphics, and each time there is a leaked CGContext, CGContextDelegate, CGColorTransform, NSBitmapGraphicsContext, and NSFocusStack (one of each).


Here is how I do it :

    CGDataProviderDirectCallbacks callbacks = {
        0,
        &MyProviderGetBytePointer,
        &MyProviderReleaseBytePointer,
        &MyProviderGetBytesAtPosition,
        &MyProviderReleaseInfo
    };

    MyProviderStruct  mps = { mBlock, mDirtyRect.X(), mDirtyRect.Y() };

    CGDataProviderRef  provider = CGDataProviderCreateDirect( &mps, sizeof(mps), &callbacks );

    NSWindow*  window = (NSWindow*)Window();
    CGImageRef  image = CGImageCreate( size_t(mDirtyRect.W()), size_t(mDirtyRect.H()), 8, 32, size_t(mBlock->Width()*4),
                                       [[window colorSpace] CGColorSpace], kCGBitmapByteOrder32Big | kCGImageAlphaNoneSkipFirst,
                                       provider, NULL, false, kCGRenderingIntentRelativeColorimetric );

    CGContextRef  myContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];

    CGContextDrawImage( myContext, CGRectMake( mDirtyRect.X(), geom.H() - mDirtyRect.Y() - mDirtyRect.H(),
                                               mDirtyRect.W(), mDirtyRect.H() ), image );

    CGContextFlush( myContext );
    CGImageRelease( image );
    CGDataProviderRelease( provider );


I don't release the CGContextRef because I don't 'create' it.
If I release it, the app doesn't crash but doesn't draw anything anymore after the first one.

My data provider just copy bytes from a legacy data structure.

What am I doing wrong ?
Or maybe there is a better way of doing this ?

Thanks for any help !

--
Keep intel OUTSIDE my Mac !
Hiii !!! I can see Intel chips creeping around my G5 !

Eric M.
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Thousands of leaked CGContext ?
      • From: David Duncan <email@hidden>
  • Prev by Date: Re: User interface unresponsive in window
  • Next by Date: Re: Scattered NSProgress use
  • Previous by thread: Re: First responder (?) problem, and orphaned highlight boxes
  • Next by thread: Re: Thousands of leaked CGContext ?
  • Index(es):
    • Date
    • Thread