Hi all,
I'm facing a memory leak problem which is like this:
I'm allocating an object of class A in class B. // RETAIN COUNT OF CLASS A OBJECT BECOMES 1
I'm placing the object in an nsmutablearray. // RETAIN COUNT OF CLASS A OBJECT BECOMES 2
In an another class C, I'm grabbing this nsmutablearray, fetching all the elements like
for(NSInteger f=0; f< [appDelegate.category_type count]; f++) { [category_type addObject:[appDelegate.category_type objectAtIndex:f]]; }
in a local nsmutablearray, releasing this first array of class B i.e. appDelegate.category_type.
// RETAIN COUNT OF CLASS A OBJECTS IN LOCAL ARRAY [category_type] BECOMES 1Now in this class C, I'm creating an object of class A and fetching the elements in local nsmutablearray like:
A *a = [[A alloc]init]; a = [category_type objectAtIndex:i];
//RETAIN COUNT OF a BECOMES 2 [ALLOCATION + FETCHED OBJECT WITH RETAIN COUNT 1]
My question is, I want to retain this array category_type which I'm displaying in tableview, and want to release it after new elements are filled in the array which I'm doing in class B. So before adding new elements, I'm removing all the elements in class B and making them nil so the references to a are now 0. And in class C I'm releasing 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.