objective c - Garbage Collector and Core Foundation -


i wrote method load image calayer. code:

- (cgimageref)loadimage:(nsstring*)path {           // data image           cgimageref image = null;           nsdata *data = [nsdata datawithcontentsoffile:path];           cfdataref imgdata = (cfdataref)data;           cgdataproviderref imgdataprovider = cgdataprovidercreatewithcfdata (imgdata);            // cgimage cfdataref           image = cgimagecreatewithjpegdataprovider(imgdataprovider, null, true, kcgrenderingintentdefault);            // if image isn't jpg image, png file           if (!image)                image = cgimagecreatewithpngdataprovider(imgdataprovider, null, true, kcgrenderingintentdefault);            return image; } 

i use method in calayer:

nsstring *pathstring = // image path; alayer = [calayer layer]; alayer.contents = [self loadimage:pathstring]; 

it's work. finalize view (using garbage collector) application has leaks. should release cfdataref imgdata? read garbage collector not work in core foundation.
, excuse english.

you responsible releasing object calling cgimagerelease.

see documentation on garbage collection:

http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/garbagecollection/articles/gccorefoundation.html

by default, therefore, in garbage-collected environment manage core foundation objects in reference-counted environment (as described in memory management programming guide core foundation > “ownership policy”). if create or copy core foundation object, must subsequently release when you’re finished it. if want keep hold of core foundation object, must retain , again subsequently release when you’re finished it.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -