开发者

How to resolve this object Leak?

开发者 https://www.devze.com 2022-12-20 05:58 出处:网络
according to picture it report an object leak 开发者_运维技巧how can i fix this issue? Don\'t use [item copy], your stories collection will retain the item copy which will over-retain the copy. Add

according to picture it report an object leak 开发者_运维技巧how can i fix this issue?

How to resolve this object Leak?


Don't use [item copy], your stories collection will retain the item copy which will over-retain the copy. Add it to stories directly, or if you must make a copy for immutability reasons, try [[item copy] autorelease].


You are copying an object and adding it to an array without decrementing its refcount, which is a leak. You should change

[stories addObject:[item copy]];

to either

[stories addObject:item];

or

[stories addObject:[[item copy] autorelease];

Depending on whether you want a copy of the item, or the item itself.

Also, next time cut and past your code so that it is readable.


Just like alloc... whenever you call a method with the word copy in it... by convention you are in charge of releasing whatever object was returned. That's all I can really make with the size of the picture.

0

精彩评论

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