加载ViewController后,应用运行缓慢,然后卸载约15-20次 [英] App running slow after loading viewcontroller, then unload about 15-20 times

查看:127
本文介绍了加载ViewController后,应用运行缓慢,然后卸载约15-20次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用: Xcode 4.6 故事板 弧 将模型设置为SecondViewController

Using: Xcode 4.6 Storyboards ARC Model segue to SecondViewController

我有一个具有主ViewController的应用程序,当设备向右旋转时,该主ViewController会加载新的veiwController.当应用启动时,一切正常.如果我旋转设备,则向后旋转以卸载secondview控制器,大约是应用程序速度的15-20倍.我缩小了范围,只有在加载第二个视图控制器时才发生,并且仅在设备旋转了十一次之后才会发生.我也缩小了范围,这是一个内存问题.我安装了一个应用程序,该应用程序跟踪已使用和可用的内存.当我多次旋转设备时,我的内存从400mb变为900mb.我正在尝试提供尽可能多的信息.每个视图都有8个NSTimer,它们每秒钟触发一次.

I have an app that has the main ViewController that loads a new veiwController when the device is rotated to the right. When the app starts everything works great. If I rotate the device, then back which unloads the secondview controller, about 15-20 times the app is very slugish. I have narrowed down that it only happenes when the seconed view controller is loaded and only when i rotate the device a nunmber of times. I also have narrowed down that is is a memory issue. I installed an app that keeps track of the memory used and available. My memory goes from 400mb to 900mb used when i rotate the device a number of times. I am trying to give as much info as I can. Each view has 8 NSTimers that fire every second.

是否可以通过编程方式卸载视图以确保正在卸载视图?

Is there a way to programmatic unload a view, to make sure is is being unloaded?

我已包含以下代码以确保加载和卸载:

I have included this code to ensure the loading and unloading:

`-(void)setView:(UIView *)aView { NSLog(@">>>输入%s<<<", PRETTY_FUNCTION );

`- (void)setView:(UIView *)aView { NSLog(@">>> Entering %s <<<", PRETTY_FUNCTION);

if (!aView)         // view is being set to nil
{
    NSLog(@"Should be unloading now");
}

[super setView:aView];

NSLog(@"<<< Leaving %s >>>", __PRETTY_FUNCTION__);

}

日志结果: 2013-04-22 16:42:03.588 xxxxxxxx [xxxxxxx] >>>输入-[GraphViewController setView:]<<< 2013-04-22 16:42:03.589 xxxxxxxx [xxxxxxx]<<<离开-[GraphViewController setView:] >>>

log result: 2013-04-22 16:42:03.588 xxxxxxxx[xxxxxxx] >>> Entering -[GraphViewController setView:] <<< 2013-04-22 16:42:03.589 xxxxxxxx[xxxxxxx] <<< Leaving -[GraphViewController setView:] >>>

` 我不确定要解决此问题需要什么.

` I am not sure what I need to be looking at to correct this.

任何朝着正确方向提出的要点"将不胜感激.

Any "points" in the right direction will be very appreciated .

谢谢

推荐答案

您尚未提供有关如何卸载" SecondViewController的大量信息.您是否也在对此进行模态搜索?如果是这样,那就是您的问题-每次执行segue时,您都实例化一个新的视图控制器,并且如果这些是模式segue,则所呈现的控制器具有指向呈现控制器的强大指针,因此这些控制器都不会被释放当您来回走动时.

You haven't given much information about how you "unload" SecondViewController. Are you doing a modal segue to it as well? If so, that's your problem -- every time you do a segue, you instantiate a new view controller, and if these are modal segues, the presented controller has a strong pointer to the presenting controller, so none of these controllers will ever get deallocated as you go back and forth.

通常,切勿使用散乱的片段在故事板上倒退.因此,解决您的问题的方法是使用放松的方法从SecondViewController返回MainViewController -这实际上将返回您来自的MainViewController的同一实例,然后SecondViewController将被释放.如果您不知道如何放松,我将编辑答案以向您展示如何进行.

As a rule, you should never go backwards in a storyboard using anything but an unwind segue. So, the solution to your problem is to use an unwind segue to go from SecondViewController back to MainViewController -- this will actually go back to the same instance of MainViewController that you came from, and SecondViewController will be deallocated. If you don't know how to make an unwind segue, I will edit my answer to show you how.

编辑后:

要想放松一下,您需要做两件事.在要返回的控制器中,添加一个方法-两件重要的事情是它是IBAction,并且它具有键入到UIStoryboardSegue *的单个参数.不管您叫什么,它甚至都不需要包含任何代码,尽管我通常在日志语句中只是为了确保它被调用而已.然后,在要解散的控制器中的IB中,控制从UI元素(如按钮或表格视图单元格)(或者如果要从代码中触发它,则从控制器本身)拖动到绿色的Exit(退出)图标场景的底部-请务必注意,您是从UI元素拖动到同一控制器中的退出图标,而不是控制器之间.放开对退出图标的拖动时,您将看到使用我上面提到的签名创建的任何方法.选择您想要的一个,就是这样.如果要将任何信息传递回目标控制器,则可以像在其他控制器中一样在源控制器中实现prepareForSegue.

To make an unwind segues, you do two things. In the controller that you're going back to, you add a method -- the two important things are that it be an IBAction, and that it has a single argument that's typed to UIStoryboardSegue*. It doesn't matter what you call it, and it doesn't even need to have any code inside it, though I usually put in a log statement just to be sure it's called. Then, in IB in the controller you're unwinding from, you control drag from your UI element like a button or table view cell (or from the controller itself if you want to fire it from code), down to the green Exit icon at the bottom of the scene -- it's important to note that you are dragging from a UI element to the exit icon in the same controller, not between controllers. When you let go of the drag over the exit icon, you will see any methods you created with the signature I mentioned above. Choose the one you want, and that's it. You can implement prepareForSegue in the source controller just like any other segue if you want to pass any information back to the destination controller.

这篇关于加载ViewController后,应用运行缓慢,然后卸载约15-20次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆