views:

153

answers:

1

Hello guys!

In the documentation I have read that I don't need to release the NSOperation object because it will be released by the NSOperationQueue, but the instruments gives me a memory leak if I don't release it in some cases, in other cases it crashes if I release. What's the problem what do you think?

+4  A: 

You have to release your copy that you created.

I assume that you are doing something like:

SomeOperation is subclass of NSOperation which does something.

- (void)start
{
    SomeOperation *so = [[SomeOperation alloc] initWithURL:url];
    [queue addOperation:so];
    [so release];
}

Apple spec:

addOperation:

...

operation

The operation object to be added to the queue. In memory-managed applications, this object is retained by the operation queue. In garbage-collected applications, the queue strongly references the operation object.

Once added, the specified operation remains in the queue until it finishes executing.

stefanB
Yes, I am doin the same code. So it needs to be released, isn't it?
Infinity
Ok, it works with release and you have right. :)Thanks a lot.
Infinity