Search code examples
objective-ciossqlitefmdb

iOS - FMDB usage and memory


I have been tracking down memory leaks in my iOS app and I keep coming back to the following code using the leaks instrument:

NSMutableArray *resultSet = [[NSMutableArray alloc] initWithCapacity:3];

NSAutoreleasePool *innerPool = [[NSAutoreleasePool alloc] init];

FMResultSet *rs = [db executeQuery:query,equipmentID];
while ([rs next])
{
    [resultSet addObject: [rs resultDict]];
}
[rs close];
[innerPool release];

return [resultSet autorelease];

Is this the correct (in terms of memory management) usage of FMDB? Here is a screenshot of the leaks instrument:

leaks

Detailed Screenshot of the leak:

detail


Solution

  • Yes, this is correct memory management. The [rs close]; line is technically unnecessary, because it will happen (if it hasn't already) when the FMResultSet is deallocated (as part of the pool draining). But putting it in there explicitly is fine.

    Is it possible you're over-retaining the return array?