我是 iPhone 开发和内存问题处理方面的新手。 我正在学习,但有些事情对我来说仍然很神秘。
在以下情况下,“Instruments”的泄漏分析器显示我的databasePath 设置中存在泄漏。我不明白为什么。
// databaseName and databasePath are properties of my class.
databaseName = [[NSString alloc] initWithString:@"sqlDbName.sql"];
NSArray *documentPaths = [[NSArray alloc] initWithArray:NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)];
NSString *documentsDir = [[NSString alloc] initWithString:[documentPaths objectAtIndex:0]];
// The problem is here :
databasePath = [[NSString alloc] initWithString:[documentsDir stringByAppendingPathComponent:databaseName]];
[documentPaths release];
[documentsDir release];
我稍后在dealloc中释放databaseName和databasePath。
我们将非常感谢您的帮助!
最佳答案
该代码是否有可能执行多次。您已在 dealloc
中释放了 databasePath
。如果此代码执行多次,则 databasePath
将会因任何连续执行而泄漏。
关于iphone - 内存泄漏问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5430703/