Re: NSGraphicsContext graphicsContextWithBitmapImageRep - Memory leak
Re: NSGraphicsContext graphicsContextWithBitmapImageRep - Memory leak
- Subject: Re: NSGraphicsContext graphicsContextWithBitmapImageRep - Memory leak
- From: Ken Thomases <email@hidden>
- Date: Sun, 09 Feb 2014 10:48:40 -0600
On Feb 9, 2014, at 4:56 AM, Dany Golubitsky wrote:
> I am having this part of code that gives me major memory leak:
>
> SBitmapImageRep* textRep = [[NSBitmapImageRep alloc]
> initWithBitmapDataPlanes:NULL
> pixelsWide:(NSInteger)frameSize.width
> pixelsHigh:(NSInteger)frameSize.height
> bitsPerSample:8
> samplesPerPixel:4
> hasAlpha:YES
> isPlanar:NO
> colorSpaceName:NSCalibratedRGBColorSpace
> bytesPerRow:0
> bitsPerPixel:0];
> [textRep setSize: frameSize];
>
> NSGraphicsContext* newContext = [NSGraphicsContext graphicsContextWithBitmapImageRep:textRep];
>
> [NSGraphicsContext saveGraphicsState];
> [NSGraphicsContext setCurrentContext:newContext];
>
>
> //
> //
> // Some drawing with openGL
> //
> //
>
>
> [NSGraphicsContext restoreGraphicsState];
>
> [textRep release];
> [newContext release];
You don't own newContext, so you're not entitled to release it.
You allocated textRep as an NSBitmapImageRep but the type of the variable is SBitmapImageRep. What is that class and why the mismatch between the actual object type and the variable type?
Doing OpenGL drawing will ignore the current NSGraphicsContext. OpenGL drawing targets the thread's current NSOpenGLContext. So why are you even creating the bitmap rep and context? Especially since you seem to just throw them away after doing the drawing. What is the point of this code?
What is the evidence that you have a memory leak and that it's due to this code? Have you tried the Leaks instrument?
Regards,
Ken
_______________________________________________
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