Releasing objects returned by method

autorelease, memory-management, objective-c

Solution

usually you would autorelease it

-(NSThing*)myMethod{

  NSThing *thing = [[NSthing alloc] init];
  // do some stuff with the thing
  return [thing autorelease];
}

Problem

Ok, I know the answer to this question should be obvious, but I need a little push in the right direction. I find myself writing a fair number of methods that follow the following pattern: ``` -(NSThing*)myMethod{ NSThing *thing = [[NSthing alloc] init]; // do some stuff with the thing return thing; } ``` My question is, how do I handle the release of this object? Clearly I can't release it within the method.

Original source