automatic ref counting - ARC from strong - to - strong -
i know correct approach here under arc.
i have strong nsarray(custom class objects of own) @property inside controller , when init controller have pass 1 nsstring these arrays controller's pointer weak. dont needed sorted
in main controller
_leftpanelviewcontroller.repotlabels = [[self.availabledashboards sortedarrayusingdescriptors:@[sortbyreportlabel]]];
and other controller has
@property(nonatomic, strong)nsarray *repotlabels;
1) understood 1st returns weak pointer assign weak pointer if code in maincontroller goes out of scope reportlabel becomes "nil"?
2) if make reportlabels property (strong) fix problem there other approach? should "copy" @ end?
_leftpanelviewcontroller.repotlabels = [[self.availabledashboards sortedarrayusingdescriptors:@[sortbyreportlabel]]copy];
i think there may confusion when property's memory management options kicks in. affect setter not getter. here's quick review using arc:
strong - object retained when setting property. previous value released. want use objects most of time want have retain on ivars no deallocated underneath, looks this:
-(void)setobject:(id)obj { [obj retain]; [_object release]; _object = obj; }
assign - used non-object values such c scalars or structs. these values , not objects, no memory management done. underneath, looks this:
-(void)setinteger:(nsinteger)newint { _nteger = newint; }
copy - new object of same type created , contents of object passed in copied. works objects conform nscopying protocol. use when want use original values of object , edit original object. (eg if have nsmutablestring set "jane" , set copied property using it, property still report "jane" after change originat nsmutablestringn "john") underneath, looks this:
-(void)setobject:(id)obj { id copy = [obj copy]; [_object release]; _object = copy; }
weak - similar assign, except when assigned object dealloced, pointer reverts nil. used in situations result in retain cycles otherwise. example, view controller setting delegate of view owns. weak used avoid both objects retaining each other , never being released.
when write object.property = value;
, [object setproperty:value]; being called behind scenes.
i suspect want use retain have listed. far can tell, no weak properties come play in code snippets have listed, unless _leftpanelviewcontroller.repotlabels
weak property.
Comments
Post a Comment