How do you fix a retain cycle? Use a weak reference. A weak reference is a pointer that does not imply ownership. To fix our retain cycle, an asset should not own its holder. Edit Asset.h to make holder a weak reference:
#import <Foundation/Foundation.h> @class Employee; @interface Asset : NSObject { NSString *label; __weak Employee *holder; unsigned int resaleValue; } @property (strong) NSString *label; @property (weak) Employee *holder; @property unsigned int resaleValue; @end
Build and run the program. Note that all the objects are now being deallocated correctly.
In a parent-child relationship, the general rule for preventing this type of retain cycle is the parent owns the child, but the child should not own the parent.