user1097185
user1097185

Reputation: 1058

CGImageRef cg = [[UIImage imageNamed: Path] CGImage]; Requires a CGImageRelease(cg)'?

I am trying to read the ARGB pixels from a an image asset in iOS. For that, I need a CGImageRef I can use to get its CGDataProvider. My question is, if I create a CGImageRef using:

CGImageRef cg = [[UIImage imageNamed: Path] CGImage];

Will I eventually need to call CGImageRelease(cg)? If I don't call CGImageRelease, will I have a memory leak?

Another issue I am having is that reading the same file for a second time returns an empty image, which I suspect might be because I didn't call CGImageRelease the first time.

Upvotes: 2

Views: 1141

Answers (2)

Daij-Djan
Daij-Djan

Reputation: 50089

no, the CGImage will be bound to the UIImage's lifetime

following cocoa's 'create rule': you only need to release what you own (objects from methods named new*, copy*, retain return an ownership)

In a addition any object from CF, follows the CF create rules (only objects from methods named Create*, Copy*, Retain)

Upvotes: 1

iDev
iDev

Reputation: 23278

You have to call CGImageRelease only when you use CGImageCreate, Copy or Retain(Or any such related method with create, copy, retain. For eg:- CGBitmapContextCreateImage). In this case, you dont have to do that since you are not doing any create, copy or retain.

Upvotes: 7

Related Questions