2 objects have references to each other, and a in B,b has a.
In the case of cyclic retain, the object cannot be freed, so only one party can use the Retain,retain for the object assign for the base type, and a reference to cat when assign does not add 1 to the Cat object counter.
Cat.h #import <Foundation/Foundation.h>@class Girl; @interface *name; @property (nonatomic,assign)int*owner; @end
CAT.M#import "Cat.h"@implementationCat- (void) dealloc{NSLog (@"The cat was released ."); [_owner release]; [Super Dealloc];}@endGirl.h#import<Foundation/Foundation.h>@classCat;//@class Cat;//just tell the compiler that cat is a cat class, and you can declare an object.//Recommendation: Later, when the header file introduces a class, it is recommended to use @class//Aimporb BIMPORTC CIMPOTD: Very low efficiency.@interfaceGirl:nsobject//In the case of cyclic retain, the object cannot be freed, and a reference to cat will not add 1 to the Cat object counter at this time only when a party uses assign,assign@property (nonatomic,assign) Cat *Cat;@endGIRL.M#import "Girl.h"@implementationGirl-(void) dealloc{NSLog (@"Girl was released"); [_cat release]; [Super Dealloc];}@endmain.m#import<Foundation/Foundation.h>#import "Girl.h"#import "Cat.h"intMainintargcConst Char*argv[]) {@autoreleasepool {Girl*g =[[Girl alloc] init]; Cat*c =[[Cat alloc] init]; G.cat= C;//The girl made a retain,c to the cat. The object counter does not add 1, C is treated as a basic type, c=1C.owner = g;//The cat had a retain,g=2 with the girl.[g release];//g=1[C release];//c=1 } return 0;}
/**/
[email protected], loop retain