ios - 应用程序的 Live Bytes 达到 1 GB 以上,模拟器显示空白屏幕

标签 ios memory malloc instruments

我在一个大项目中工作。直到最后一个小时都没有问题。突然间,我的应用程序的事件字节数不断增加,达到 1 GB 以上,我什至无法确定问题出在哪里。我已经搜索并找到了 this 但它用于整体字节而不是实时字节。

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

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

这是 Instruments 的屏幕截图,您可以看到实时字节达到 1 GB。

enter image description here

我已经尝试了以下步骤
  • 重置模拟器的内容和设置
  • 删除 Xcode 完整的应用程序文件
  • 删除所有派生文件并彻底清理垃圾
  • 重新安装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];
            }
        }
    
    
    }
    

    什么都没奏效。任何人都可以说问题是什么?

    最佳答案

    我在这个 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;
    

    您不能再次使用相同的填充 View 。您必须为 UserPasswordFld 再次分配它 field 。采取另一个填充 View 并使用它,然后它将起作用。

    关于ios - 应用程序的 Live Bytes 达到 1 GB 以上,模拟器显示空白屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20921191/

    相关文章:

    memory - gdb & 找出内存地址何时被写入

    c - 如何从内存中正确分配结构

    c - 索引 'mallocced' 数组时出现段错误

    ios - 应用程序未从 .plist 文件中删除一行

    java - 循环登录的字符串会污染内存吗?

    ios - UInavigationcontroller 全局警报消息(如 WhatsApp 传入消息)

    java - 了解 JVM 中的对象开销

    C 链表 valgrind 大小读取无效

    ios - NSMutableData 从 Objective-C 中的 JSON 响应中获取键值

    ios - 确定 UILabel 中有多少个字符已被截断