RAGOpoR
RAGOpoR

Reputation: 8168

How to resolve this object Leak?

according to picture it report an object leak how can i fix this issue?

alt text

Upvotes: 0

Views: 129

Answers (3)

Louis Gerbarg
Louis Gerbarg

Reputation: 43452

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.

Upvotes: 3

dreamlax
dreamlax

Reputation: 95355

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].

Upvotes: 3

Ryan Ferretti
Ryan Ferretti

Reputation: 2961

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.

Upvotes: 0

Related Questions