I sent an email to the list earlier asking about CoreAnimation memory use. I think I have that all resolved now, except for one memory usage issue with CARenderer.

I am successfully rendering a layer tree that is never shown on the screen with a CARenderer. I set up a pixel buffer, and then render to the pixel buffer. But, when I call [CATransaction commit] before I actually do the rendering, there is a very large allocation of memory depending on the size of the image. Apparently glClear is being called internally by CoreAnimation, and I'm guessing it's allocating some sort of buffer internal to CoreAnimation. I can't figure out how to get CoreAnimation to let go of it, and it exists for the lifetime of my program.

Here is the complete event log of the memory at the address in question (note the lack of a free event): # Category Event Type Timestamp Address Size Responsible Library Responsible Caller 0 GeneralBlock-36003840 Malloc 00:14.930 0x254cf000 36003840 libGL.dylib glClear

The stack trace from where the memory is allocated:
   0 libSystem.B.dylib malloc
   1  0x179b1e3c
   2  0x179a37d8
   3  0x179a6af1
   4 libGL.dylib glClear
5 MyProgram -[GSOGLLayerRenderer imageByRenderingLayers:] / Users/....
   6 MyProgram -[GSImageExporterController prepareImage] /Users/....
   7 MyProgram -[MyDocument export:] /Users/....
   8 AppKit -[NSApplication sendAction:to:from:]
   9 AppKit -[NSMenu performActionForItemAtIndex:]
10 AppKit -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:]
  11 AppKit AppKitMenuEventHandler
12 HIToolbox DispatchEventToHandlers(EventTargetRec*, OpaqueEventRef*, HandlerCallRec*) 13 HIToolbox SendEventToEventTargetInternal(OpaqueEventRef*, OpaqueEventTargetRef*, HandlerCallRec*)
  14 HIToolbox SendEventToEventTarget
15 HIToolbox SendHICommandEvent(unsigned long, HICommand const*, unsigned long, unsigned long, unsigned char, OpaqueEventTargetRef*, OpaqueEventTargetRef*, OpaqueEventRef**)
  16 HIToolbox SendMenuCommandWithContextAndModifiers
  17 HIToolbox SendMenuItemSelectedEvent
18 HIToolbox FinishMenuSelection(MenuData*, MenuData*, MenuResult*, MenuResult*, unsigned long, unsigned long, unsigned long, unsigned char) 19 HIToolbox MenuSelectCore(MenuData*, Point, double, unsigned long, OpaqueMenuRef**, unsigned short*)
  20 HIToolbox _HandleMenuSelection2
  21 HIToolbox _HandleMenuSelection
  22 AppKit _NSHandleCarbonMenuEvent
  23 AppKit _DPSNextEvent
24 AppKit -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]
  25 AppKit -[NSApplication run]
  26 AppKit NSApplicationMain
  27 MyProgram main /Users/....
  28 MyProgram start

Here are the relevant snippets of my code (with the line the large memory allocation occurs on noted):
NSOpenGLPixelFormatAttribute attr[] =
{
        NSOpenGLPFAOffScreen,
        NSOpenGLPFADepthSize, 24,
        (CGLPixelFormatAttribute) 0
};
NSOpenGLPixelFormat *format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr]; m_glContext = [[NSOpenGLContext alloc] initWithFormat:format shareContext:nil]; m_renderer = [CARenderer rendererWithCGLContext:[m_glContext CGLContextObj] options:NULL];
[m_renderer retain];
[m_glContext retain];
m_renderFrame = frame;
int imageWidth = ceil(m_renderFrame.size.width);
int imageHeight = ceil(m_renderFrame.size.height);
int imageSize = imageWidth*imageHeight*4;
glData = malloc(GL_ALIGN(imageSize));
[m_glContext setOffScreen:glData width:imageWidth height:imageHeight rowbytes:imageWidth*4];
NSOpenGLContext *oldContext = [NSOpenGLContext currentContext];
[oldContext retain];
[m_glContext makeCurrentContext];
glClearColor(0, 0.0, 0.0, 0.0);
glViewport (0.0, 0.0, imageWidth, imageHeight);
glLoadIdentity ();
glOrtho (frame.origin.x, frame.origin.x+imageWidth, frame.origin.y, frame.origin.y+imageHeight, -1, 1);
....some more setup code here....
[m_glContext makeCurrentContext];
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
[CATransaction commit]; <-large memory allocation occurs here
[m_renderer beginFrameAtTime:0.0 timeStamp:NULL];
[m_renderer addUpdateRect:CGRectMake(m_renderFrame.origin.x, m_renderFrame.origin.y, imageWidth,imageHeight)];
[m_renderer render];
[m_renderer endFrame];
glPixelStorei(GL_PACK_ALIGNMENT, 1);
...read the pixels here...

If anyone had any suggestions, or could let me know what's going on here, I'd appreciate it. I'm really bad with pixel buffers, and I'm not sure why. Something about drawing something I can't see disagrees with me I guess. :)

Thanks,
Colin
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to