NSOperation not being fully deallocated? Live Bytes not less than Overall Bytes in Allocations Utility despite operations completing

StackOverflow https://stackoverflow.com/questions/5812466

문제

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?

도움이 되었습니까?

해결책

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.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top