Circular references were one of my pet pegs before, and they don’t usually cause your page to crash, but they do cause occasional crashes, so they have to be fixed in the absence of something more urgent. The following provides a workaround for the following circular references:

A, instruments,

Xy asked me to find the details of the circular quote, damn! Open Xcode –product– Profile and click Leaks. Click on the loop reference page you want to view to find the code associated with the loop reference. Change the relevant code to a weak reference

Advantages: fast, effortless
Disadvantages: also too fast, some can not be found, need artificial observation

So if you’re checking for cyclic references, this should be the first step.

RAC circular reference

Weakify (self) is very convenient, but there is also a bit of pit (is also my own careful, take it for sure), @weakify(self) WHEN I first use it, I think it is equivalent to a weak function, but also feel very convenient, all use rewrite self can directly weak reference, this is not a magic tool is what? Weakify (self) {weakify(self) {weakify(self) {weakify(self) {weakify(self) {weakify(self) {weakify(self) {weakify(self) {weakify(self) {weakify(self) {weakify(self) {weakify(self) {weakify(self) {weakify(self); What is the specific reason I am referring to xy provide analysis of the RAC @Weakify, @Strongify document know

Third, violent modification

This method was discovered by XY, and I think this method can not be found in the face of a large number of code recommended use: replace all self in the code with wself and then slowly change this method according to the error to solve the self loop is not bad.

Loop references to non-self

In addition to VC circular references if you have time to write all the other classes to check circular references, it may not be as effective as VC, but better than nothing. I checked the calendar page and found that every class in the calendar page was released except for the HotelChoiceChildAgeView class which doesn’t call Dealloc but this class code is very simple, it doesn’t have a loop reference itself it’s less than 100 lines, I’ve been looking for all of them so there’s a possibility of using this class and I’m strong-referencing it

AgeView *child = [AgeView new];
                child.sequenceLab.text = [NSString stringWithFormat:@"The %@ bit",[self intergerToChinese:i]];
                [arrM addObject:child];
                @weakify(self)
                [[child rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
                    @strongify(self)
                    [self choiceAge:child index:(i-1)];
                }];
Copy the code

The inside of this block was @strongify(self), but this method also references child, so chlid needs a weak reference, too, to make sure HotelChoiceChildAgeView can be released as:

AgeView *child = [AgeView new];
                child.sequenceLab.text = [NSString stringWithFormat:@"The %@ bit",[self intergerToChinese:i]]; [arrM addObject:child]; @weakify(self,child) [[child rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl *  _Nullable x) { @strongify(self,child) [self choiceAge:child index:(i-1)]; }];Copy the code

So self doesn’t release and maybe some other class strong-referenced it. The best way to do this is to create a dealloc breakpoint for each class. If you do not release the dealloc breakpoint for each class, it will be difficult to find the problem

The above is only my experience, please lightly spray ~