App running slow after loading viewcontroller, then unload about 15-20 times(加载 viewcontroller 后 App 运行缓慢,然后卸载约 15-20 次)
问题描述
使用:Xcode 4.6故事板弧模型转至 SecondViewController
Using: Xcode 4.6 Storyboards ARC Model segue to SecondViewController
我有一个应用程序,它的主 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 的信息.您是否也在对其进行模态搜索?如果是这样,那就是你的问题——每次你做一个转场,你实例化一个新的视图控制器,如果这些是模态转场,呈现的控制器有一个指向呈现控制器的强指针,所以这些控制器都不会被释放来回走动.
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.
作为一项规则,你不应该在情节提要中使用任何东西来倒退,而不是使用 unwind segue.因此,您的问题的解决方案是使用展开转场从 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 元素(如按钮或表格视图单元格)(或者如果您想从代码中触发它,则从控制器本身)拖动到绿色的退出图标场景的底部——重要的是要注意,您是从 UI 元素拖动到同一控制器中的退出图标,而不是控制器之间.当您松开退出图标上的拖动时,您将看到您使用我上面提到的签名创建的任何方法.选择你想要的,就是这样.如果您想将任何信息传递回目标控制器,您可以像任何其他 segue 一样在源控制器中实现 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 后 App 运行缓慢,然后卸载约 15-20 次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:加载 viewcontroller 后 App 运行缓慢,然后卸载约 15-20 次
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01