Delegate property declared with a strong reference
ID |
objectivec.correctness.delegate_should_be_weak |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Resource Management |
Language |
Objective-C |
Description
A delegate or data source property must not own its target. The delegate almost always owns the object it is a delegate of, so a strong reference back to it closes a cycle and neither object is ever deallocated. Declare the property weak - or assign/unsafe_unretained when the target is a non-object or a class that predates weak references.
Rationale
A delegate or data source property must not own its target. The delegate almost always owns the object it is a delegate of, so a strong reference back to it closes a cycle and neither object is ever deallocated. Declare the property weak - or assign/unsafe_unretained when the target is a non-object or a class that predates weak references.
The following code illustrates the pattern detected by this rule:
@interface FeedController ()
// FLAGGED: Delegate property declared with a strong reference
@property (nonatomic, strong) id delegate;
@end
@implementation FeedController
@end