Dealloc weak nil

#import <UIKit/UIKit.h>
#import "AppDelegate.h"
@interface B : NSObject
@end
@implementation B
- (void)dealloc
{
    NSLog(@"in dealloc");
}
@end

@interface A  : NSObject
@property(nonatomic, weak)id referObj;
- (void)foo;

@end

@implementation A
- (void)foo
{
    B*b = [B new];
    self.referObj = b;
    NSLog(@"%@",b);
}
@end
int main(int argc, char * argv[]) {
    @autoreleasepool {
        A*a = [A new];
        [a foo];
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

  

原文地址:https://www.cnblogs.com/wxm5558/p/5543743.html