【问题标题】:Live Bytes of app reaches above 1 GB and simulator shows blank screen应用程序的 Live Bytes 达到 1 GB 以上,模拟器显示空白屏幕
【发布时间】:2014-01-22 03:48:02
【问题描述】:

我正在从事一个大项目。直到最后一个小时都没有问题。突然间,我的应用程序的活动字节数不断增加,超过 1 GB,我什至无法确定问题出在哪里。我已经搜索并找到了this,但它是针对整体字节而不是实时字节。

五分钟后我收到以下错误:

xxxxxx(1456,0x252d1a8) malloc: *** mach_vm_map(size=8388608) failed (error code=3)
*** error: can't allocate region

这是 Instruments 的屏幕截图,您可以看到 live bytes 达到 1 GB。

我已经尝试了以下步骤

  1. 重置模拟器的内容和设置
  2. 删除 Xcode 完整的应用程序文件
  3. 删除所有派生文件并彻底清理垃圾
  4. 重新安装 Xcode

为了更正确在这行中发现错误

- (void)viewDidLoad
{
    [super viewDidLoad];

    [UserNameTxtFld setBackgroundColor:[UIColor colorWithRed:242.0f/255.0f green:245.0f/255.0f blue:245.0f/255.0f alpha:1.0]];

    [UserPasswordFld setBackgroundColor:[UIColor colorWithRed:242.0f/255.0f green:242.0f/255.0f blue:242.0f/255.0f alpha:1.0]];

    [LoginButton setBackgroundColor:[UIColor colorWithRed:60.0f/255.0f green:179.0f/255.0f blue:113.0f/255.0f alpha:1.0]];

    //[ForgotButton setBackgroundColor:[UIColor lightGrayColor]];

    API=[[BMAPIClass alloc] init];
    API.delegate    =   self;

    UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, UserNameTxtFld.frame.size.height)];

    UserNameTxtFld.leftView = paddingView;

    UserPasswordFld.leftView =paddingView;

    self.appDelegate   =   (BMAppDelegate*)[[UIApplication sharedApplication] delegate];

    //Set Splash screen

    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
        CGSize result = [[UIScreen mainScreen] bounds].size;
        if(result.height == 480)
        {
            // iPhone Classic
            NSLog(@"iphone 4");

            if(IS_RETINA)
            {
                NSLog(@"Yes retina Display");
                splashScreenImage.image =[UIImage imageNamed:@"splash_640x960.jpg"];
                [visiblePassword setBackgroundImage:[UIImage imageNamed:@"eye_640x960.png"] forState:UIControlStateNormal];

            }
            else
            {
                NSLog(@"Not retina Display");
                splashScreenImage.image =[UIImage imageNamed:@"splash_320x480.jpg"];
                [visiblePassword setBackgroundImage:[UIImage imageNamed:@"eye_320x480.png"] forState:UIControlStateNormal];
            }
        }
        if(result.height == 568)
        {
            // iPhone 5
            NSLog(@"iphone 5");
            splashScreenImage.image =[UIImage imageNamed:@"splash_640x1136.jpg"];
            [visiblePassword setBackgroundImage:[UIImage imageNamed:@"eye_640x1136.png"] forState:UIControlStateNormal];
        }
    }


}

没有任何效果。谁能说说问题出在哪里?

【问题讨论】:

  • 您是否使用 Instruments 来查看哪些对象是实时字节分配的一部分以及创建它们的代码是什么?
  • 希望最近几个小时不是代码 bcz 我从来没有接触过代码我确定我在 UI 中更改了一些东西,之后只会出现这个问题
  • 检查您是否不小心启用了 NSZombies。昨天我想知道为什么我的应用程序需要千兆字节的 RAM,结果我打开了 NSZombies。
  • 仪器挂满了,所以我看不到是哪个对象造成了问题,无法进一步检查
  • 您的代码有问题。

标签: ios memory malloc instruments


【解决方案1】:

我在这个Link看到了你的代码

根据您给定的代码,您多次使用相同的代码。

    UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, UserNameTxtFld.frame.size.height)];

    UserNameTxtFld.leftView = paddingView;

    UserNameTxtFld.leftViewMode =UITextFieldViewModeAlways;

    UserPasswordFld.leftView =paddingView; // this is wrong(can't use it again)
    UserPasswordFld.leftViewMode =UITextFieldViewModeAlways;

您不能再次使用相同的填充视图。您必须为 UserPasswordFld 字段再次分配它。获取另一个填充视图并使用它,然后它就可以工作了。

【讨论】:

  • tnx 指导我很多
  • 很高兴为您提供帮助。
猜你喜欢
  • 2019-08-21
  • 1970-01-01
  • 2014-06-23
  • 1970-01-01
  • 1970-01-01
  • 2017-04-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多