【发布时间】:2014-05-21 08:34:49
【问题描述】:
NSString *strongObj = [[NSString alloc] init]; //alloc and initialze a new instance
strongObj = @"some value"; //set value to a instance
__weak NSString *weakObj = strongObj; //refer strong pointer to weak obj
strongObj = nil; //set strong object to nil and remove it from memory
strongObj = @"some value 2"; //assign a different value to strong obj
weakObj ; // weak obj still holds // @"some value" // this value event i've set the week obj pointer to nil
请看上面的代码和 cmets,这些 cmets 是我的观点/假设。请澄清。
谢谢
【问题讨论】:
-
弱对象将保留该值,直到其生命周期和范围存在。在范围({ 和 })之后,它将被自动释放并添加到本地或最近的自动释放池。然后它将被释放/释放。
标签: ios objective-c memory-management