i m little confused on memory management in following scenario
-(NSData *)getData{
NSData *TempData = [[NSData alloc]init];
return TempData;
}
//in some other method
NSData *NewData = [self getData];
now the question is till when NewData will be retained and how should i release it?
This is wrong usage of this getter method.
It should return an autoreleased copy of NSData. The autoreleased copy may or maynot be retained by the caller. Incase it is retained, its the caller’s responsibility to release it.
Secondly a typo in return of this method, it should be NSData*.
My typo in return. Thanks to Peter Sarnowski for pointing.
The caller can retain it by using the following code:
In case caller is not interested in retaining this object, he will just call
and use within the same function from where it is called.