简体   繁体   English

iOS-FMDB使用和内存

[英]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: 我一直在追踪我的iOS应用程序中的内存泄漏,并使用泄漏工具继续返回以下代码:

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? 这是正确的(就内存管理而言)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]; [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). 从技术上讲,该行是不必要的,因为当FMResultSet被释放时(作为池排放的一部分),它将发生(如果尚未发生)。 But putting it in there explicitly is fine. 但是将其明确地放在那里是很好的。

Is it possible you're over-retaining the return array? 您是否可能过度保留return数组?

SQLite allocates and keeps a bunch of memory, which is only freed when the database is closed. SQLite分配并保留了一堆内存,只有在关闭数据库时才会释放该内存。 You can also adjust how much memory it will allocate by issuing a 'pragma cache_size = nnn' command. 您还可以通过发出“ pragma cache_size = nnn”命令来调整它将分配多少内存。

See this related question and answer: 请参阅以下相关问答:

memory leak (?) after sqlite+fmdb vacuum command sqlite + fmdb vacuum命令后出现内存泄漏(?)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM