This is a very good question to ask, because in Objective-C there is no garbage collector. We have to manually handle the memory.
You own an object in Objective-C when you alloc
it, copy
it or new
it. For example (I've copied this example code from http://interfacelab.com/objective-c-memory-management-for-lazy-people/):
-(void)someMethod
{
// I own this!
SomeObject *iOwnThis = [[SomeObject alloc] init];
[iOwnThis doYourThing];
// I release this!
[iOwnThis release];
}
-(void)someOtherMethod:(SomeObject *)someThing
{
// I own this too!
SomeObject *aCopyOfSomeThing = [someThing copy];
[aCopyOfSomeThing doSomething];
// I release this!
[aCopyOfSomeThing release];
}
-(void)yetAnotherMethod
{
// I own this too!
SomeObject *anotherThingIOwn = [SomeObject new];
[anotherThingIOwn doSomething];
// I release this!
[anotherThingIOwn release];
}