NSOperation 没有完全释放?尽管操作已完成,但分配实用程序中的实时字节数不少于总体字节数

发布于 2024-11-03 14:33:10 字数 916 浏览 1 评论 0原文

我正在运行大量 NSOperation 任务,并且我的应用程序使用了大量内存。虽然它应该使用相当多的量,但它使用的量级超过了应有的量级,而且我认为,从 Instruments 来看,这是因为 NSOperation 对象没有被完全释放。我的 NSOperation 子类的代码如下:

- (id)initFromNode:(BKObject *)sender withNumber:(NSNumber *)number; {
  self = [super init];
  if (self) {
    _number = [number retain];
    _sender = [sender retain];
  }
  return self;
}
- (void)main {
  [_sender go:_number];
}
- (void)dealloc {
  [_number release];
  _number = nil;
  [_sender release];
  _sender = nil;
  [super dealloc];
}

我的怀疑是这样的,因为在 Instruments 中,当我使用分配实用程序时,它显示了我的 _NSOperationInternal 的大量数据,并且也是我的 NSOperation 子类,但活动字节数始终等于总体字节数。我还检查了 Leaks 实用程序,它从未发现任何内存泄漏。在将操作对象添加到队列后释放它们时,我会非常小心。

我还陷入了一个完成块来测试它是否真正完成,并且我可以确认至少其中一些确实完成了。确认所有这些数据将需要更多工作,而且 Instruments 中的实时数据应该会稍微下降,即使只有(比如其中 10%)完成。

我不知所措。如果我对自己正在做的事情的理解有误,或者更多代码是否会有帮助,请告诉我。您知道这会使用比应有的内存更多的内存吗?

I'm running a large number of NSOperation tasks and my application is using a great deal of memory. While it should use quite a bit, it's using magnitudes more than it should, and I'm thinking, from Instruments, that it's because the NSOperation objects aren't being fully deallocated. The code for my NSOperation subclass is as such:

- (id)initFromNode:(BKObject *)sender withNumber:(NSNumber *)number; {
  self = [super init];
  if (self) {
    _number = [number retain];
    _sender = [sender retain];
  }
  return self;
}
- (void)main {
  [_sender go:_number];
}
- (void)dealloc {
  [_number release];
  _number = nil;
  [_sender release];
  _sender = nil;
  [super dealloc];
}

My suspicions are as such because in Instruments, when I use the Allocations utility, it shows enormous amounts of data for my _NSOperationInternal and also my subclasses of NSOperation, but the Live Bytes number is always equal to the Overall Bytes number. I've also checked with the Leaks utility, which never finds any memory leaks. I'm careful about releasing any operation objects after adding them to the queue.

I also stuck in a completion block to test it out if it actually finishes, and I can confirm that at least some of them do. Confirming all of them would be more work, and the live data in Instruments should go down a bit, even if only, say 10% of them, were finishing.

I'm at a loss. Let me know if any of my understanding of what I'm doing is off or if more code would be helpful. Do you know what might be going on that this is using more memory than it should?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

离笑几人歌 2024-11-10 14:33:11

要调试此问题,请尝试查看 -dealloc 是否被调用。最简单的方法是使用 NSLog,正确的方法是断点。

我的猜测是:

  • 您没有正确释放 NSOperations
  • 或者你有保留周期。
  • NSOperation 中的某些对象没有被释放,请尝试在 main 方法周围添加自动释放池。

To debug this, try to see if -dealloc gets even called. The simplest way to do this is to use an NSLog, the correct way would be a breakpoint.

My guesses are:

  • You're not correctly releasing the NSOperations.
  • or you've got retain cycles.
  • Some objects in your NSOperation don't get released, try adding an autorelease pool around your main method.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文