Retain count problem iphone sdk

Posted by neha on Stack Overflow See other posts from Stack Overflow or by neha
Published on 2010-06-10T06:08:46Z Indexed on 2010/06/10 6:12 UTC
Read the original article Hit count: 499

Hi all,

I'm facing a memory leak problem which is like this:

  1. I'm allocating an object of class A in class B. // RETAIN COUNT OF CLASS A OBJECT BECOMES 1

  2. I'm placing the object in an nsmutablearray. // RETAIN COUNT OF CLASS A OBJECT BECOMES 2

  3. In an another class C, I'm grabbing this nsmutablearray, fetching all the elements in that array in a local nsmutablearray, releasing this first array of class B. // RETAIN COUNT OF CLASS A OBJECTS IN LOCAL ARRAY BECOMES 1

  4. Now in this class C, I'm creating an object of class A and fetching the elements in local nsmutable array. //RETAIN COUNT OF NEW CLASS A OBJECT IN LOCAL ARRAY BECOMES 2 [ALLOCATION + FETCHED OBJECT WITH RETAIN COUNT 1]

My question is, I want to retain this array which I'm displaying in tableview, and want to release it after new elements are filled in the array. I'm doing this in class B. So before adding new elements, I'm removing all the elements and releasing this array in class B. And in class C I'm releasing object of class A in dealloc.

But in Instruments->Leaks it's showing me leak for this class A object in class C.

Can anybody please tell me wheather where I'm going wrong.

Thanx in advance.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about memory-management