美文网首页
循环retain

循环retain

作者: MarkTang | 来源:发表于2016-01-09 00:53 被阅读45次
    
    #import <Foundation/Foundation.h>
    #import "Person.h"
    #import "Dog.h"
    int main(int argc, const char * argv[]) {
        @autoreleasepool {
            Person *p = [[[Person alloc]init]autorelease];
            Dog *d = [[[Dog alloc]init]autorelease];
            p.dog = d;
            d.person = p;
        }
        return 0;
    }
    #import <Foundation/Foundation.h>
    @class Dog;
    @interface Person : NSObject
    @property(nonatomic,retain)Dog *dog;
    @end
    #import "Person.h"
    #import "Dog.h"
    @implementation Person
    - (void)dealloc
    {
        self.dog = nil;
        
        NSLog(@"%s",__func__);
        [super dealloc];
    }
    @end
    #import <Foundation/Foundation.h>
    @class Person;
    @interface Dog : NSObject
    @property(nonatomic,assign)Person * person;
    @end
    #import "Dog.h"
    #import "Person.h"
    @implementation Dog
    - (void)dealloc
    {
    //    self.person = nil;
        NSLog(@"%s",__func__);
        [super dealloc];
    }
    @end
    

    相关文章

      网友评论

          本文标题:循环retain

          本文链接:https://www.haomeiwen.com/subject/mvxqkttx.html