10

I am creating an NSArray inside a method, so I have to give it up with release when I'm done with it. I pass this array to the

- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay

method. After that, I don't need the array anymore in my method that calls this performSelector:withObject:afterDelay:.

The documentaton doesn't say if anArgument is going to be retained, so I wonder if I had to autorelease it or retain it in order to stay alive. What do you think?

  • 2
    Quick comment: autorelease wouldn't help anyways because who knows how long the delay would be. It would almost assuredly be longer than the run loop takes to complete. – Corey Floyd Aug 06 '09 at 21:40
  • 1
    `-performSelector:withObject:afterDelay:` is guaranteed to run on the next cycle of the run loop (even if the delay is 0.0 seconds), which should mean that the autorelease pool will be emptied. – Nick Forge Feb 22 '11 at 07:22

1 Answers1

17

The performSelector methods retain their receiver and argument.

Nick Veys
  • 23,458
  • 4
  • 47
  • 64