gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 20:42:51 26 4
gpt4 key购买 nike

如何解决此内存泄漏...我什至在最后释放它,如图片所示,但它仍然存在。在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com