简体   繁体   English

管理弹出式控制器及其内容视图的内存

[英]Managing memory for popover controllers and their content views

When the user taps on the right callout accessory on my map view's pin's callout I am showing a popovercontroller with a view inside it. 当用户在我的地图视图的图钉标注上点击正确的标注配件时,我将显示一个内部带有视图的popovercontroller。 I am maintaining 2 retained properties in the mapcontroller for this. 我为此在mapcontroller中维护2个保留的属性。 I am also releasing these properties in dealloc of the mapcontroller - which probably never happens. 我还在mapcontroller的dealloc中释放这些属性-可能永远不会发生。

When the user deselects the annotation view I want all this memory released, does assigning nil suffice? 当用户取消选择注释视图时,我要释放所有这些内存,分配nil是否足够?

- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view
{
    [self.informationViewController.view removeFromSuperview]; //remove from popovercontroller
    self.informationViewController = nil; 
    popoverController = nil;
}

Yes, it should. 是的,应该。 This sets the reference of the object to nil which in turn releases the object. 这会将对象的引用设置为nil,从而释放对象。 I'm no expert on memory management though, so if anyone wants to downvote/correct me, feel free. 我不是内存管理专家,所以如果有人想对我进行投票/纠正,请放心。

I believe you also will need to release the objects. 我相信您也将需要释放对象。

Wouldn't just assigning nil only remove your pointer to the object in memory? 不只是分配nil只会删除指向内存中对象的指针吗? I suspect the object would still reside in memory and still have a retain counter assigned to it, so it will not be removed from memory until it's retain count was decremented. 我怀疑该对象仍将驻留在内存中,并且仍为其分配了一个保留计数器,因此在保留计数递减之前,它不会从内存中删除。

Further, by assigning your pointer to nil before you released the object, I also would suspect that you will have created a memory leak because the attempt to call release in the dealloc of the controller will not actually release the object. 此外,通过在释放对象之前将指针分配给nil,我还怀疑您会造成内存泄漏,因为在控制器的dealloc中调用release的尝试实际上不会释放该对象。

I'm not 100% sure about this, but ... here is also a link to the Memory Management Programming Guide . 我对此不是100%的确定,但是...这也是《 内存管理编程指南》的链接。

Also, for the future, if you want to be sure, you could run your application using the Leaks performance tool, it should show you where you're leaking memory and what objects are currently allocated in memory, etc... 另外,将来,如果您想确定的话,可以使用Leaks性能工具运行您的应用程序,它应该显示泄漏内存的位置以及内存中当前分配了哪些对象等。

I could try to setup the scenario in a test project real quick and monitor it using Leaks and update my answer later also. 我可以尝试在测试项目中真正快速地设置场景,并使用Leaks进行监视,并稍后再更新答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM