In my app I want to copy a custom class from one array to another array. So I implemented copyWithZone for this class. Xcode analyze warning me that every line with [alloc] or [copy] are leaking memory. How can I tell if it’s really leaking or it’s the copied instance that I need?
@implementation MyClass
- (id)copyWithZone:(NSZone *)zone {
MyClass *copy = [[MyClass allocWithZone:zone] init];
if (copy){
copy.uniqueId = [uniqueId copy];
}
return copy;
}
Is your
uniqueIdproperty declared as a retain property? If so, this line is leaking:Change it to: