苹果手机 : how to solve this memory leak?

标签 iphone objective-c ios memory-management instruments

如何解决此内存泄漏...我什至在最后释放它,如图片所示,但它仍然存在。在 if 语句几乎 10-15 条件下,它像给定的代码一样使用......但最后我发布了它。

enter image description here

LoginResponse *response = [[LoginResponse alloc] initWithMessageString: messageString];


ServerMessage *ackMessage = [[ServerMessage alloc] initWithMessageToAck:response];
[[NSNotificationCenter defaultCenter] postNotificationName:@"SendMessageToServer" object:ackMessage];

[[NSNotificationCenter defaultCenter] postNotificationName:@"LoginResponseReceived" object:response];

最佳答案

没有释放messageString。你在做什么是这样的:

// there's a messageString
if(...){
     NSString* messageString= [[NSString alloc] init ... ]
                                   // you're declaring new messageString, 
                                   // not related to the outer messageString
     ...
     // and you didn't release the inner messageString. 
     // The pointer messageString just goes away.
}
[messageString release]; // you're releasing outer messageString, not inner messageString.

从 XCode 执行“分析”。 (它在“构建”菜单项下方。)我认为这应该解决忘记释放内部 messageString 的问题。在运行仪器之前使用“分析”。

关于苹果手机 : how to solve this memory leak?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7714394/

相关文章:

ios - App审核时Apple是如何检测UDID访问的?

objective-c - 从 UITabBarController 中删除所有项目

ios - 如何从 NSDate 中删除时区偏移量

ios - CocoaPods 不适用于框架目标

ios - 单击选项卡时,选项卡栏 Controller 不显示 XIB UIViewController

ios - 允许在超过 2 个 View 上导航

iphone - 如何关闭 AirPrint 弹出窗口?

iphone - 使用 iPhone 应用程序中的过渡将对象移动到触摸

iphone - 为什么我无法使用此代码从委托(delegate)获取上下文?

objective-c - 应用图标问题上的远程通知角标(Badge)