运行应用程序时内存消耗不断增加 [英] Memory consumption keeps increasing while running application

查看:197
本文介绍了运行应用程序时内存消耗不断增加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序中使用各自的视图控制器拥有多个视图。我正在做的事情如下。



这里是更具说明性的代码:

 -(void)applicationDidFinishLaunching:(UIApplication *)application 
{
View1Controller * viewController1 = [[View1Controller alloc] initWithnibName:@ View1];
View2Controller * viewController2 = [[View2Controller alloc] initWithnibName:@ View2];
View3Controller * viewController3 = [[View3Controller alloc] initWithnibName:@ View3];

[window addSubview:viewController1.view];
[window makeKeyAndVisible];
}

在View1Controller文件中:



对于某些按钮操作

 -(IBAction)goTOView2:(id)sender 
{
iPhoneApplicationAppDelegate * appDelegate =(iPhoneApplicationAppDelegate *)[[UIApplication sharedApplication]委托];
[appDelegate.window.superView removeFromSuperview];
[appDelgate.window addSubview:appDelgate.viewController2.view];
}

类似地用于视图3



<我将所有这三个视图控制器保留在我的应用程序委托中。当我想切换到其他视图时,我有以下代码。



不要继续写代码的语法错误。



此三视图控制器具有多视图,并带有自己的导航控制器,用于推送和弹出不同的视图。



我的问题是,当我使用仪器运行该应用程序时,我看到当我从一个视图切换到另一个视图时,内存消耗一直在增加。



请提前提供帮助和感谢。

解决方案

此该行看起来不正确:

  [appDelegate.window.superView removeFromSuperview]; 

您想要的东西是:

  [viewController1.view removeFromSuperview]; 

取决于您要移开的视图。


I have multiple views in my application with respective view controllers. What I am doing is as follows.

Here is the more illustrative code:

- (void)applicationDidFinishLaunching:(UIApplication *)application
{
  View1Controller *viewController1 = [[View1Controller alloc] initWithnibName:@"View1"];
  View2Controller *viewController2 = [[View2Controller alloc] initWithnibName:@"View2"];
  View3Controller *viewController3 = [[View3Controller alloc] initWithnibName:@"View3"];

  [window addSubview:viewController1.view];
  [window makeKeyAndVisible];
}

In View1Controller file:

For Some Button Action

- (IBAction) goTOView2:(id)sender
{
  iPhoneApplicationAppDelegate *appDelegate = (iPhoneApplicationAppDelegate*) [[UIApplication sharedApplication] delegate];
  [appDelegate.window.superView removeFromSuperview];
  [appDelgate.window addSubview: appDelgate.viewController2.view];
}

Similarly for view3

I am retaining all this three view controller in my application delegate. When I want to switch to other view I have the following code.

Don't go on the syntax errors of the code.

This three view controller has multiple view with their own navigation controller which for pushing and popping different views.

My problem is when I run this application using instrument, I see as I switch from one view to another the memory consumption keeps increasing.

Please help and thanks for that in advance.

解决方案

This line looks wrong:

[appDelegate.window.superView removeFromSuperview];

What you want is something like:

[viewController1.view removeFromSuperview];

depending on which view you're moving away from.

这篇关于运行应用程序时内存消耗不断增加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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