在設備上測試我的應用程序它返回一個泄漏時,我打電話給自定義對象的副本ande我無法理解爲什麼。iPhone - copyWithZone泄漏
這是調用:
NSMutableArray *arr = [[NSMutableArray alloc] initWithCapacity:5];
for (SinglePart *sp in [copyFrom partList]) {
[arr addObject:[sp copy]];
}
self.partList = arr;
[arr release];
這是該方法:
- (id)copyWithZone:(NSZone *)zone {
SinglePart *copy = [[[self class] allocWithZone:zone] initWithSinglePart:self];
[copy loadImage];
return copy;
}
這是受copyWithZone調用的方法:
- (id)initWithSinglePart:(SinglePart *)copyFrom {
if (self = [super init]) {
self.imagePath = [copyFrom.imagePath copy];
self.color = [UIColor colorWithCGColor:copyFrom.color.CGColor];
self.hasOwnColor = copyFrom.hasOwnColor;
self.blendingMode = copyFrom.blendingMode;
}
return self;
}
非常感謝......我真的需要進一步瞭解內存管理。你能建議一些鏈接嗎? :) – w4nderlust 2010-10-12 16:48:36
http://developer.apple.com/library/ios/#documentation/cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html – 2010-10-12 16:52:50