我在下面的代碼中有內存泄漏。在樂器本身墜毀之前,我得到了87.5%的內存泄漏。也許你們中的一個可以告訴我這段代碼有什麼問題。我需要在這裏發佈任何東西嗎?謝謝。分配在方法之間傳遞的Core Data managedobject時發生內存泄漏
- (void)browseSSviewControllerDidFinish:(browseSSviewController *)controller {
<SNIP>
MANAGED_OBJECT_1 = [self newFormatFromFormat:MANAGED_OBJECT_2];
<SNIP>
}
- (Format *)newFormatFromFormat:(Format *)formatToCopy {
NSLog(@"making new format that's a copy");
Format *thisNewFormat = [self newBlankFormat];
[self updateFormat:thisNewFormat withNumbersFromFormat:formatToCopy];
return thisNewFormat;
}
-(void)updateFormat:(Format *)formatToCopyTo withNumbersFromFormat:(Format *)formatToCopyFrom {
NSLog(@"copying formats");
formatToCopyTo.x = formatToCopyFrom.x;
formatToCopyTo.y = formatToCopyFrom.y;
formatToCopyTo.z = formatToCopyFrom.z;
formatToCopyTo.a = formatToCopyFrom.a;
formatToCopyTo.n = formatToCopyFrom.n;
formatToCopyTo.u = formatToCopyFrom.u;
formatToCopyTo.s = formatToCopyFrom.s;
}
- (Format *)newBlankFormat {
NSLog(@"making new blank format");
gfghfAppDelegate *del = (gfghfAppDelegate *)[UIApplication sharedApplication].delegate;
NSManagedObjectContext *MOC = del.managedObjectContext;
NSPersistentStoreCoordinator *PSC = [MOC persistentStoreCoordinator];
NSManagedObjectModel *MOM = [PSC managedObjectModel];
NSEntityDescription *entity = [[MOM entitiesByName] objectForKey:@"Format"];
Format *thisNewFormat = [[NSManagedObject alloc] initWithEntity:entity insertIntoManagedObjectContext:MOC];
thisNewFormat.slot = [NSNumber numberWithInt:-1];
NSLog(@"slot = %@",thisNewFormat.slot);
return thisNewFormat;
}
這裏是我能儀器之前離開我回溯的泄漏的87.5%墜毀:
+0xc7 calll DYLD-STUB$$objc_msgSend = 87.5%
我沒有使用mutableCopy複製我的MANAGED_OBJECTs因爲它只是沒有工作。
PS - MANAGED_OBJECT_1和MANAGED_OBJECT_2都是實例變量 - 自定義的屬性查看控制器對象。 – CommaToast