开发者

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


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?


SQLite allocates and keeps a bunch of memory, which is only freed when the database is closed. You can also adjust how much memory it will allocate by issuing a 'pragma cache_size = nnn' command.

See this related question and answer:

memory leak (?) after sqlite+fmdb vacuum command

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜