Peter Johnson
Peter Johnson

Reputation: 3786

Puzzling memory leak when adding image to a contact on IOS

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([UIImage 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.

Upvotes: 3

Views: 590

Answers (1)

YPK
YPK

Reputation: 1851

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.

Upvotes: 1

Related Questions