Featured post
objective c - CGImage, NSArray and Memory -
this multiple part question, because ignorance on matter has multiple layers.
first, put caching system caching cgimageref
objects. keep @ cgimageref
level (rather uiimage
) loading images in background threads. when image loaded put nsmutabledictionary
. had bit of arm twisting cgimageref
's array:
//bunch of stuff drawing context cgimageref imageref = cgbitmapcontextcreateimage(context); cgcontextrelease(context); [(id)imageref autorelease]; [self.cache setobject:(id)imageref forkey:@"somekey"];
so, can see, i'm trying treat image ref nsobject
, setting autorelease placing in dictionary. expectation allow image cleaned after being removed dictionary. now, beginning have doubts.
my application clears cache array when user "restarts" play different images. running application in instruments shows memory not dropping "start" level on restart, instead remains steady. gut tells me when array has objects removed cgimageref
not being cleared.
however, i'm unable confirm don't quite know how track down actual source of memory in instruments. it's list of (malloc 16 bytes, malloc 32 bytes, etc), drilling them show list of dyld callers. not sure how read it.
so, first question, way of caching cgimageref
objects flawed? , there better way confirm such things in instruments?
first of all, caching cgimages ok , don't see problems code posted.
am correctly assuming use nsmutabledictionary
cache? if so, can clear sending -removeallobjects
, should release keys , values. if set different images same keys, memory usage may remain same because replace previous images new ones. if images have same size, memory usage should constant except brief spikes when create new batch of images.
as instruments, i've seen both report false positives , miss real leaks. try running several times, making pauses, if possible, leaks instrument "catch up". sounds crazy, think may make bit more reliable.
if else fails, can log contents of cache before , after loading set of images make sure cache works expected.
- Get link
- X
- Other Apps
Comments
Post a Comment