ios - Strong Class Objects inside for loop is not retaining in ARC -


i have manual reference count project, few classes im converting arc removing retain,release & etc , setting compiler flag “-fobjc-arc” 2 arc(-fobjc-arc) enabled view controller classes, classa , classb.

i allocating , initialising objects of classb inside classa within loop achieve functionality, code snippet below,

@interface classa ()  @property (strong, nonatomic) classb *classbobj;  @end   @implementation classa  - (void)createclassbview {     (int count = 0; count <= [dataobject count]; count++) //if count more 1 not retaining previous classbobj     {         classbobj = [[classb alloc] init]; //arc keeping 1 object reference of class need retain iterated objects         [self.scrollview addsubview:classbobj withframe:myframe];//only 1 view getting added subview if control comes here more once     } }  @end 

the above code works fine me in non-arc(mrc) fails work when arc enabled. not retaining classb objects if strong,

only 1 object i.e; last iterated classb object reference alive, rest getting destroyed , throwing exception "classb reference deallocated instance"

i tried using if(!classbobj){classbobj = [[classb alloc] init];} inside loop, time i'm not getting classb reference deallocated instance exception 1 subview of classb getting added scrollview(i.e; last iterated).

please guide me on this. appreciated in advance.

your code doing telling do. setting same reference, self.classbobj, classb instance - on , over, in loop. each time through loop, existing classb instance assigned self.classbobj needs "get out of way" new 1 can assigned self.classbobj. rightly released when replaced new 1 - rightly, because there no existing reference it.

the truth totally mismanaging memory here before arc, , adopting arc has revealed fact. you're lucky code ever worked (or seemed to). if want maintain multiple classb instances, need instance variable array of them, not single one.

(on other hand, if classbobj uiview , added interface subview, still happening, it's hard see complaint is. indeed, weird part why ever needed classbobj property in first place; why isn't local variable? it's not need these references retained elsewhere, since have references — subviews of self.scrollview. if need references later purpose, , if don't want obtain them using fact subviews of scroll view, need array of them, said.)


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -