NSString内存泄漏问题,如何自动释放NStstring?
我的程序中有一些 NSString 。如果我发布了一个版本,我认为它已完成使用,它就会使程序崩溃。如果我不释放它们,则会导致大量内存泄漏。 [string1 autorelease] 导致执行错误访问。
这让我很头疼。
I have some NSString inside my program. If I did a release I think its finished using, it crashed the program. If I don't release them , it cause memory leakage quite a bit.
[string1 autorelease] cause executive bad access.
It giving me all kinds of headache.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
release 和 autorelease 都是释放,只是时间点不同。因此,如果其中一台崩溃,另一台很可能也会崩溃。
您需要正确地进行内存管理。也许使用 NSZombies,静态分析器也可能是一个好帮手。此外,调试器可能会立即停止在导致问题的对象处。
我建议阅读内存管理指南: http:// developer.apple.com/library/mac/documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html
release and autorelease is both releasing, just at different points in time. So if one crashes, most likely the other one will as well.
You need to get your memory management right. Maybe use NSZombies, and the static analyzer might be a good helper, too. Also, the debugger might stop right away at the object that causes the problems.
I suggest to read the memory management guide: http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html