Frage

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.

War es hilfreich?

Lösung

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.

Andere Tipps

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)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top