How the release works in projects based on ARC

I know that there are many questions on this subject. I have never worked on a project not based on ARC.

I have a strong and weak property as follows

@property(strong,nonatomic)NSArray *data1; @property(unsafe_unretained, nonatomic)NSArray *data2; 

I have seen that in some places people explicitly do nil data in viewDidUnload.

i.e

 -(void)viewDidUnload{ self.data1=nil; self.data2=nil; } 

My question is: if I do not do this in my case (I mean, if I do not do data1 and data2 is zero

in viewDidUnload), will ARC automatically open objects?

+4
source share
2 answers

Yes, ARC will automatically release all properties / variables of a strong link immediately before the destruction of the parent object. As for "weak" links, they are not saved / not freed (which is the same with or without ARC).

Setting self.data1 = nil in viewDidUnload usually not needed, but sometimes you want to make it obvious to show where the selected object is called. If you want to make sure your data1 released right here in this line of code, use the code that you have. If you do not care when and where it was released, you do not need.

+2
source

Yes, they will be released when your view controller is released. viewDidUnload (no longer called iOS 6) does not match dealloc , and it is not the "opposite" viewDidLoad - it was called only in low memory situations when the view was turned off.

Any memory-hogging transient objects should be set to zero in didReceiveMemoryWarning - ARC will not do this automatically for you.

+3
source

Source: https://habr.com/ru/post/1436288/


All Articles