Objective C 的Reference Counting



NSMutableArray *lplp = [[NSMutableArray alloc] init];
     NSMutableArray *lplp2 = [[NSMutableArray alloc] init];
    
    
      NSLog(@"1 %d",[lplp retainCount]); //0
    UIImageView *dd=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1.jpeg"]]; 
      NSLog(@"2 %d",[dd retainCount]); //1
    [lplp addObject:dd];
      NSLog(@"3 %d",[dd retainCount]);
    [lplp2 addObject:dd];
      NSLog(@"4 %d",[dd retainCount]);
    NSString *fileLocation = [[NSBundle mainBundle] pathForResource:@"2" ofType:@"png"];
    NSData *imageData = [NSData dataWithContentsOfFile:fileLocation];

一直對objective c的reference counting參考模式很不習慣

留言

這個網誌中的熱門文章

Office 2021 離線安裝封裝與KMS啟動步驟

Ollama使用心得與模型導入教學

ARC下NSMutableDictionary 無法使用retainCount