views:

75

answers:

1

Hi I am getting memory leak in Instruments for the following line of code .

 NSArray *itemsList=[[NSArray alloc] initWithObjects:@"Love",
     @"Hate",@"Happy",@"Sad",
     @"Desire",@"Anger",@"Hope",@"Fear",@"Silly",nil];

I am using the below code: arrayList is also released in dealloc block.

NSArray *itemsList=[[NSArray alloc] initWithObjects:@"Love",@"Hate",
    @"Happy",@"Sad",@"Desire",
    @"Anger",@"Hope",@"Fear",@"Silly",nil];
self.arrayList=itemsList;
[itemsList release];
+1  A: 

I'm assuming that arrayList is declared using retain in the @property statement. If not, then that is certainly your problem.

If it is, then you have a leak, but not in the code you've posted. It's important to realize that Instruments first shows not necessarily where the leak occurred, but where the leaked memory was allocated. You'll have look through the rest of your uses of arrayList and find where you have a retain that's missing a release.

If you click on the arrow next to the memory address of the object in Instruments, you should be able to see everywhere that your object was retained and released. You'll have look through them and identify which retain is missing a release.

Robot K
Probably just forgot to release arrayList in -(void) dealloc.
w.m
w.m: The question says “arrayList is also released in dealloc block.”
Peter Hosey
Right, sorry. Must've missed that.
w.m