UIPoverController 每次使用时都会创建实时字节

发布于 2024-12-19 08:36:59 字数 1072 浏览 3 评论 0原文

我正在事件处理程序上弹出 Popover 控制器。每次调用此事件处理程序时,我的应用程序的内存占用量都会增加。一旦我关闭视图控制器,我期望内存占用量会减少,但它永远不会发生。

我使用 Instruments 中的分配工具来分析内存。

我在这里做错了什么吗?

-(IBAction)createNewAccount :(id) sender
{

    GSNewAccountViewController *createNewAccountVC = [[GSNewAccountViewController alloc]initWithNibName:@"GSNewAccountViewController" bundle:nil];        
    UIPopoverController *popover = 
    [[UIPopoverController alloc] initWithContentViewController:createNewAccountVC]; 

    popover.popoverContentSize = CGSizeMake(kScrollViewWidth, kScrollViewHeight);

    [popover presentPopoverFromRect:CGRectMake(770,-420,320,480) inView:self.view permittedArrowDirections: UIPopoverArrowDirectionUp animated:YES];

    popover.delegate = self;

    [createNewAccountVC release];


}

- (void)popoverControllerDidDismissPopover:
(UIPopoverController *)popoverController {

    [popoverController release];

}

更新:

我正在其 ViewDidUnload 方法中释放 GSNewAccountController 的所有 Outlet。但即使当我关闭 Popovercontroller 时, vieUnDIdload 方法也不会被调用

I am popping up the Popover controller on an event handler. Each time this event handler gets called, the Memory footprint of my application grows. Once I dismiss the View controller , I expect the memory footprint to be reduced, but it never happens.

I used the Allocations tool in Instruments to Profile the memory.

Am I doing anything wrong here?

-(IBAction)createNewAccount :(id) sender
{

    GSNewAccountViewController *createNewAccountVC = [[GSNewAccountViewController alloc]initWithNibName:@"GSNewAccountViewController" bundle:nil];        
    UIPopoverController *popover = 
    [[UIPopoverController alloc] initWithContentViewController:createNewAccountVC]; 

    popover.popoverContentSize = CGSizeMake(kScrollViewWidth, kScrollViewHeight);

    [popover presentPopoverFromRect:CGRectMake(770,-420,320,480) inView:self.view permittedArrowDirections: UIPopoverArrowDirectionUp animated:YES];

    popover.delegate = self;

    [createNewAccountVC release];


}

- (void)popoverControllerDidDismissPopover:
(UIPopoverController *)popoverController {

    [popoverController release];

}

UPDATE:

I am releasing all the Outlets of the GSNewAccountController in the ViewDidUnload method of it. But even when I dismissing the Popovercontroller the vieUnDIdload method does not get called

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橪书 2024-12-26 08:36:59

您应该检查在 popoverController 释放时您的 GSNewAccountViewController 是否也被释放。检查活动 GSNewAccountViewController 对象的数量,而不是监视活动字节数。要在“分配工具”中执行此操作,请转到“工具”窗口的右上角,通过在文本字段中键入 GSNewAccountViewController 来过滤分配。然后检查每次触发 IBAction 时会发生什么。当您触发 IBAction 时,生活数应变为 1,并在释放 popoverController 时返回到零。

如果活动 GSNewAccountViewController 对象的数量永远不会变为零,您应该检查是否在 GSNewAccountViewController 类中创建了某种类型的保留循环,该循环阻止调用 dealloc 和 viewDidUnload 方法。通过保留周期,GSNewAccountViewController 会保留一个对象,而该对象又会保留您的 GSNewAccountViewController。由于两者都互相保留,因此不会调用它们的 dealloc 方法,并且对象永远不会被销毁。

为了测试,尝试创建一个非常简单的 iPad 项目,在主视图上有一个按钮,并使用 IBAction 来呈现一个 popoverController,其中包含一个从带有 UITableViewController 的普通子类的 NIB 加载的 viewController。查看分配工具,它显示当显示 popoverController 时正在创建子类,并在关闭 popoverController 时销毁子类。

祝你好运

You should check to see if your GSNewAccountViewController is being released when the popoverController is released. Rather than monitoring the amount of Live Bytes, check the # of living GSNewAccountViewController objects. To do this in the Allocations Instrument go to the upper right corner of the Instruments window, filter the allocations by typing GSNewAccountViewController in the text field. Then check to see what happens every time you trigger the IBAction. The # of living should go to 1 when you trigger the IBAction and go back to zero when the popoverController is released.

If the # of living GSNewAccountViewController objects never goes to zero you should check to see if you have created some sort of retain cycle within your GSNewAccountViewController class that is preventing the dealloc and viewDidUnload methods to be called. With the retain cycle, the GSNewAccountViewController is retaining an object, which in turn, is retaining your GSNewAccountViewController. Since both are retaining each other, their dealloc methods are not being called and the objects are never destroyed.

To test, try creating a very simple iPad project with a button on the main view with an IBAction to present a popoverController with a viewController loaded from a NIB with a plain vanilla subclass of a UITableViewController. Looking at the Allocations instrument, it shows that the subclass is being created when the popoverController is shown and destroyed when the popoverController is dismissed.

Good luck

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文