retain-cycle

Retain Cycle in ARC

情到浓时终转凉″ 提交于 2019-11-27 01:38:40
I have never worked on non ARC based project. I just came across a zombie on my ARC based project. I found it was because of retain cycle.I am just wondering what is a retain cycle.Can Could you give me an example for retain cycle? A retain cycle is a situation when object A retains object B , and object B retains object A at the same time * . Here is an example: @class Child; @interface Parent : NSObject { Child *child; // Instance variables are implicitly __strong } @end @interface Child : NSObject { Parent *parent; } @end You can fix a retain cycle in ARC by using __weak variables or weak

How to Correctly handle Weak Self in Swift Blocks with Arguments

时间秒杀一切 提交于 2019-11-26 19:24:48
In my TextViewTableViewCell , I have a variable to keep track of a block and a configure method where the block is passed in and assigned. Here is my TextViewTableViewCell class: // // TextViewTableViewCell.swift // import UIKit class TextViewTableViewCell: UITableViewCell, UITextViewDelegate { @IBOutlet var textView : UITextView var onTextViewEditClosure : ((text : String) -> Void)? func configure(#text: String?, onTextEdit : ((text : String) -> Void)) { onTextViewEditClosure = onTextEdit textView.delegate = self textView.text = text } // #pragma mark - Text View Delegate func

Referring to weak self inside a nested block

China☆狼群 提交于 2019-11-26 13:00:36
问题 Suppose I already create a weak self using __weak typeof(self) weakSelf = self; [self doABlockOperation:^{ ... }]; Inside that block, if I nest another block: [weakSelf doAnotherBlockOperation:^{ [weakSelf doSomething]; } will it create a retain cycle? Do I need to create another weak reference to the weakSelf? __weak typeof(self) weakerSelf = weakSelf; [weakSelf doAnotherBlockOperation:^{ [weakerSelf doSomething]; } 回答1: It depends. You only create a retain cycle if you actually store the

Retain Cycle in ARC

半世苍凉 提交于 2019-11-26 12:28:27
问题 I have never worked on non ARC based project. I just came across a zombie on my ARC based project. I found it was because of retain cycle.I am just wondering what is a retain cycle.Can Could you give me an example for retain cycle? 回答1: A retain cycle is a situation when object A retains object B , and object B retains object A at the same time * . Here is an example: @class Child; @interface Parent : NSObject { Child *child; // Instance variables are implicitly __strong } @end @interface