开发者

Puzzling memory leak when adding image to a contact on IOS

开发者 https://www.devze.com 2023-02-10 21:09 出处:网络
I currently have a leak on this line in instruments, I leak a few hundred K each time this is called-

I currently have a leak on this line in instruments, I leak a few hundred K each time this is called-

NSData *dataRef = UIImagePNGRepresentation([UIImage imageNamed:@"Icon.png"]);
ABPersonSetImageData(newRecord, (CFDataRef)dataRef, nil);

When I rem out the above lines, I'm good.

dataRef is only mentioned here in the entire program. I tried CFrelease-ing it as a test, but that causes a crash due to referencing a deallocated object.

i tried concatenating it all into one line,

ABPersonSetImageData(newRecord,(CFDataRef) UIImagePNGRepresentation([UIImag开发者_运维百科e imageNamed:@"Icon.png"]), nil);

but I got the same results.

I would half-expect a leak the first time, as Imagenamed is well known to cache the image object, and the call was reported to leak pre-iOS4, but I wouldn't expect ongoing leaks.

Any ideas? related questions have been raised here before a few times but no-one seemed to have an answer.


I think you need not to worry about that object. Since UIImagePNGRepresentation will return you an autoreleased object, so there won't be any memory leak. Since dataRef is an autoreleased object you should not release it manually.

0

精彩评论

暂无评论...
验证码 换一张
取 消