QCRenderer Memory Leak

Thomas Neugebauer's picture

Even if it's connected my with last post, I create a new post for it.

I am taking snapshots of my composition with

- (NSBitmapImageRep*) bitmapImageForTime:(NSTimeInterval)time
{
   //Render a frame from the composition at the specified time
   if(![_renderer renderAtTime:time arguments:nil])
   return nil;
 
   //Grab a snapshot of rendered image
   return [[_renderer createSnapshotImageOfType:@"NSBitmapImageRep"] autorelease];
}

An "autorelease pool" is in place in "main", but the app eats and eats memory and finally ends with "Terminating app due to uncaught exception 'NSMallocException', reason: 'NSImage: Insufficient memory to allocate pixel data buffer of 3686400 bytes'"

I also tried to manually release the "bitmap data" - with no effect.

I even tried (just for testing):

...
NSBitmapImageRep *test;
 
test=[_renderer createSnapshotImageOfType:@"NSBitmapImageRep"];
[test release];

Same effect - I am lost - am I doing something fundamentally wrong?

Thanks

vade's picture
Re: QCRenderer Memory Leak

Im assuming you are looping through the frames, so you have something like.

NSAutoReleasePool* pool = [[NSAutoReleasePool alloc] init];
 
for(int i = 0; i < numFramesIWantToRender; i++)
{
   // render code and make temporary images;
}
 
[pool drain];

Now, you dont have a run loop, and you dont have a timer, which means all of the memory is released only when the loop terminates

solution, put a temporary NSAutoReleasePool and drain it for every iteration in your rendering, this way memory is cleared each frame, and not only at the end.

I suspect thats your issue.

Thomas Neugebauer's picture
Re: QCRenderer Memory Leak

Yap - you were right. In fact for testing, I did a "[pool drain]" every n. iteration within my loop, but while moving code around, I screwed up my "mod condition".

So thanks for you hint - solved my problem. Shame on me.