In my program the memory is leaking while adding the place1 in the mapArray1
I have released the mapArray1 in dealloc method. then also leaking where I have to release the mapArray1?
place1 = [[NSMutableDictionary alloc] init];
for(i=0;i<[array count];i++)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[place1 setObject:@"1" forKey:@"ID"];
lati=[array1 objectAtIndex:i];
[place1 setObject:lati forKey:@"latitude"];
long i = [array2 objectAtIndex:i];
[place1 setObject:longi forKey:@"longitude"];
[mapArray1 addObject:[place1 copy]];
[pool release];
}
The leak is coming from
[place1 copy]. Either replace it with[[place1 copy] autorelease]or use a temporary variable and release it after you add it to mapArray1.From the docs:
You take ownership of an object if you create it using a method whose name begins with “alloc”, “new”, “copy”, or “mutableCopy” (for example, alloc, newObject, or mutableCopy), or if you send it a retain message.
Also, I doubt you need to recreate those autorelease polls in each cycle…