我正在编写iOS应用程序。我有班级汽车和班级轮。 Class Car有一个属性Wheel(仅在本例中,实际上,Car有多个轮子)。
在课堂上:
@property (nonatomic, retain) Wheel * wheel; //because it has retain, so I delete wheel in dealloc function.
当我有一个Car对象时,我开始使用。
Car* car = [[Car alloc] init];
car.wheel = [[Wheel alloc] init];
我认为该代码会产生泄漏内存,但XCode中的仪器工具中的泄漏检测器工具无法检测到它。那么,发生了什么?可能是我错了?
感谢您的帮助。
答案 0 :(得分:1)
由于您声明了wheel
属性以保留给定的对象,因此向autorelease
对象发送Wheel
消息:
Car* car = [[Car alloc] init];
car.wheel = [[[Wheel alloc] init] autorelease];