由于您的属性是使用(保留)定义的,因此您使用合成设置器(通过 self.overlay 语法)设置的任何实例都将自动发送保留消息:
// You're alloc'ing and init'ing an object instance, which returns an
// instance with a retainCount of 1.
UIView *tempOverlay = [[UIView alloc] initWithFrame:CGRectMake(160.0f, 70.0f, 150.0f, 310.0f)];
// The overlay property is defined with (retain), so when you assign the new
// instance to this property, it'll automatically invoke the synthesized setter,
// which will send it a retain message. Your instance now has a retain count of 2.
self.overlay = tempOverlay;
// Send a release message, dropping the retain count to 1.
[tempOverlay release];
如果你要这样做:
self.overlay = [[UIView alloc] initWithFrame:CGRectMake(160.0f, 70.0f, 150.0f, 310.0f)];
您的叠加层将保留计数为 2,这可能会导致应用程序中的某个点发生泄漏。