Memory management in ObjC/iPhone
Posted
by Manu
on Stack Overflow
See other posts from Stack Overflow
or by Manu
Published on 2010-03-16T05:44:26Z
Indexed on
2010/03/16
5:46 UTC
Read the original article
Hit count: 596
iphone
Hi,
I have question in memory management (objective C). There are two ideal scenario.
============================= scenario 1 ======================================== (void) funcA { MyObj *c = [otherObj getMyObject]; [c release]; }
-(MyObj *) getMyObject //(this method is available in other OtherObj.m file) { MyObj *temp = [[MyObj alloc] init]; // do smothing here return temp; }
============================= scenario 2 ======================================== (void) funcA { MyObj *c = [otherObj getMyObject]; }
-(MyObj *) getMyObject //(this method is available in other OtherObj.m file) { MyObj *temp = [[myObj alloc] init]; // do smothing here return [temp autorelease]; }
myObj is holding huge chunk of data.
In first scenario I am getting myObj(allocated) from other file so I have to release in my own method. (as per any C/C++ language library ,like strdup will return string duplicate which will realase later by developer not by strdup method).
In second scenario I am getting myObj(allocated) from otherObj.m file so otherObj.m file is responsible to release that allocated memory(mean autorelease)? Is it right?
Please let me know Which scenario is more efficient and valid as per apple memory guidelines. Please Please don't show me any document link.
Thanks Manu
© Stack Overflow or respective owner