RE: NSGraphicsContext graphicsContextWithBitmapImageRep - Memory leak
RE: NSGraphicsContext graphicsContextWithBitmapImageRep - Memory leak
- Subject: RE: NSGraphicsContext graphicsContextWithBitmapImageRep - Memory leak
- From: Dany Golubitsky <email@hidden>
- Date: Mon, 10 Feb 2014 03:16:58 -0500
- Acceptlanguage: en-US
- Thread-topic: NSGraphicsContext graphicsContextWithBitmapImageRep - Memory leak
Hello Ken and thanks for your answer!
1) SBitmapImageRep is actually NSBitmapImageRep. N is just get lost in Copy. Sorry.
2) I tried both with release and without release of newContext. Same effect.
3) I am sorry for misguide a little. The drawing is not entirely with openGL. The simple story is that we need to draw text. We can not do it with openGL, so what we do is - we create another context with NSBitmapImageRep, we draw the text there, than we draw the texture with openGL.
At that point, we would like to release both textRep and newContext since we do not need them anymore.
4) I know that this is memory leak since application memory is constantly growing up to 2GB (Maybe even more). I run it with Leaks instrument. It does not recognize it as leak, only as allocation.
If I comment this part of code memory size reduces dramatically.
Regards
Dany
-----Original Message-----
From: Ken Thomases [mailto:email@hidden]
Sent: Sunday, February 09, 2014 18:49
To: Dany Golubitsky
Cc: email@hidden
Subject: Re: NSGraphicsContext graphicsContextWithBitmapImageRep - Memory leak
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