vishal mali
vishal mali

Reputation: 31

How to release memory associated by CGImageCreateWithImageInRect

I am using CGImageCreateWithImageInRect() for generating a small image from a background image runtime, which is going to displayed for every thread call (0.01 sec). Once I start showing part of image through CGImageCreateWithImageInRect application starts consuming memory in very high rate and crashes within seconds. Memory consumed goes to 20+ MB and crashes. Normal application would run on 2MBs.

Image1 = CGImageCreateWithImageInRect(imageRef, CGRectMake(x, y, w, h));

and after processing I do

CGImageRelease(Image1);

but it is not helping me.

I want to know how to release memory associated with CGImageCreateWithImageInRect.

Upvotes: 3

Views: 2148

Answers (2)

Actually, that pair of lines are not balanced, since CGImageCreateWithImageInRect() retains the original image. It should be…

CGImageRef Image1 = CGImageCreateWithImageInRect(imageRef, CGRectMake(x, y, w, h));
CGImageRelease(imageRef);
...
CGImageRelease(Image1);

Upvotes: -1

smorgan
smorgan

Reputation: 21569

The answer to your question is in fact CGImageRelease; the pair of lines you have excerpted from your code are correctly balanced. You must be leaking somewhere else.

Upvotes: 4

Related Questions