NSDate 造成内存泄漏

发布于 2024-11-30 03:47:21 字数 382 浏览 1 评论 0原文

我已经浏览了已经发布的问题,并且有很多我尝试使用的提示。不幸的是我没有解决这个问题。

我只有以下代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

自由如风 2024-12-07 03:47:21

只写

self.timestamp = [NSDate date];

而不是给定的代码块,它将工作而不会泄漏。

Write only

self.timestamp = [NSDate date];

instead of given code block,it will work without leak.

耳钉梦 2024-12-07 03:47:21

[timestamp release] 是否在您的 dealloc 实现中? IE:

-(void)dealloc {
  // ... your other retained property/ivar releases ... //
  [timestamp release];
  [super dealloc];
}

此外,如果您在标准 iOS 项目中运行,则不需要设置自己的 NSAutoreleasePool (除非您处于紧密循环或线程实现中)。

is [timestamp release] in your dealloc implementation? IE:

-(void)dealloc {
  // ... your other retained property/ivar releases ... //
  [timestamp release];
  [super dealloc];
}

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).

鸠魁 2024-12-07 03:47:21

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"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文