NSDate 造成内存泄漏
我已经浏览了已经发布的问题,并且有很多我尝试使用的提示。不幸的是我没有解决这个问题。
我只有以下代码:
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSDate *date = [[NSDate alloc] init];
self.timestamp = date;
[date release];
[pool release];
但 NSDate 的分配行仍然存在内存泄漏。我在没有 AutoreleasePool 的情况下进行了尝试,我尝试使用排出池而不是释放池,我什至尝试使用静态 NSDate 日期方法。但我并没有摆脱内存泄漏。
我还是不明白。非常感谢任何帮助。
I was already browsing through the questions alreaded posted and there were a lot of hints I tried to work with. Unfortunately I don't get the issue solved.
I simply have the following code:
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSDate *date = [[NSDate alloc] init];
self.timestamp = date;
[date release];
[pool release];
But still there is a memory leak at the allocation line of NSDate. I tried it without the AutoreleasePool, I tried using drain instead of release for the pool, I even tried to use the static NSDate date methode. But I do not get rid of the memory leak.
I still don't get it. Any help is highly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只写
而不是给定的代码块,它将工作而不会泄漏。
Write only
instead of given code block,it will work without leak.
[timestamp release]
是否在您的dealloc
实现中? IE:此外,如果您在标准 iOS 项目中运行,则不需要设置自己的
NSAutoreleasePool
(除非您处于紧密循环或线程实现中)。is
[timestamp release]
in yourdealloc
implementation? IE:Also, if you're running in a standard iOS project, you shouldn't need to set up an
NSAutoreleasePool
of your own (unless you're in a tight loop or a thread implementation).ObjectiveC for iOS 中的内存管理只是引用计数。如果您发现“Apple的内存管理有点令人畏惧” ” 然后试试这个 - “Cocoa 的简单内存管理工具”
Memory Management in ObjectiveC for iOS is just reference reference counting. If you find "Apple's Mem Management a bit daunting" then try this - "Simple Memory Management Tools for Cocoa"