In wikipedia example author has released the object stats, when it has not been allocated, copied, or retained. Is this an error or something I don’t understood?
- (IBAction)analyzeDocument:(NSButton *)sender
{
dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSDictionary *stats = [myDoc analyze];
dispatch_async(dispatch_get_main_queue(), ^{
[myModel setDict:stats];
[myStatsView setNeedsDisplay:YES];
[stats release];
});
});
}
It is either an error or it is properly documented that
analyzereturns ownership of the object to the caller. If it is not an error thatstatsis released then that codes example is using a convention that goes against Apple’s memory management rules for ownership.Another prefix that should return ownership is the class method
+new. E.g.[MyDocClass newAnalysis];