You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
645 B
31 lines
645 B
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:
|
|
|
|
```objectivec
|
|
@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 properties
|
|
for your "back links", i.e. links to direct or indirect parents in an object
|
|
hierarchy:
|
|
|
|
```objectivec
|
|
@class Child;
|
|
@interface Parent : NSObject {
|
|
Child *child;
|
|
}
|
|
@end
|
|
@interface Child : NSObject {
|
|
__weak Parent *parent;
|
|
}
|
|
@end
|
|
```
|