iphone - 内存泄漏问题

标签 iphone objective-c xcode memory-leaks

我是 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/

相关文章:

iphone - Objective-C/Cocoa Touch 中的 HTML 字符解码

iphone - 为什么图像没有显示在 UIImageView 中

iphone - 访问/设置iOS设置应用的全局设置

ios - UITableView & Controller 给我空 TableView

ios - 委托(delegate)一致性和 MFMailComposeViewController

ios - ld : framework not found FirebaseAuth error due to residual firebase components

iphone - 提交加密应用到AppStore前需要准备什么?

ios - PFObject 子类未在解析仪表板中创建新类

c++ - Xcode 预处理器宏以包含系统样式 header

ios - 在 iOS 应用程序上安装谷歌分析时出错