3

I've been using an NSOperationQueue and I have very strange memory issue with it. I've tried reducing the issue to the simplest possible probleme and here I got:

in init:

_queue = [[NSOperationQueue alloc] init];

Later:

TestOperation op = [[TestOperation alloc] init];
[self.queue addOperation: op];

then in the method called by the main of the operation:

NSLog(@"I'm right here!");

If I call this thousands of times, my memory used just keep growing.

I've I only remove the NSLog from my method (thus calling an empty method) my memory don't change.

What am I doing wrong here??

SeikoTheWiz
  • 853
  • 1
  • 10
  • 27
  • is op also a member of the class or it is inside a function? I see that you are declaring queue as though it was inside a function but then you are doing something like self.queue which I means queue is a property of the class. – aichamorro May 12 '15 at 14:25
  • Yes Sorry, Corrected it, I just tried to put the lines that mattered here. Went too fast. – SeikoTheWiz May 12 '15 at 14:27
  • what you call thousand times? Did you start your operation queue. I smell you keep adding operations to a queue you never started. – MadNik May 12 '15 at 14:46
  • Yes it is started and the print is printed in the console. I have a simple for loop that call a thousand time the method creating an operation and adding it to the queue. See my other comment below for a possible explanation (I'm currently still investigating) about the memory growth. – SeikoTheWiz May 12 '15 at 14:54

1 Answers1

1

When you add an operation to an NSOperationQueue, the operation queue owns the object and will be responsible of releasing it. Perhaps you are not giving enough time to the NSOperationQueue to release the memory and see the results?

For this cases you can surrounded it with an @autorelease block, but since the operation queue is the one responsible for the release of the objects I don't know if it will work. Is worth a try.

aichamorro
  • 71
  • 4
  • I just figured something (even though it doesn't explain why it's not changing memory in an empty method). My queue capacity is growing with the number of simultaneous operation I store in it. So the memory it takes doesn't change even after treating all operations. I think I need to find a way to change the capacity of it's operations NSArray. – SeikoTheWiz May 12 '15 at 14:37