由于内存警告而崩溃甚至在仪器中显示7-8 MB>>使用ARC进行分配

时间:2013-08-05 05:28:50

标签: iphone ios objective-c memory-management out-of-memory

我的应用程序因接收内存警告而多次崩溃,即使它显示分配的实时字节为7-8 MB,如屏幕截图所示。 enter image description here 即使在搜索了所有相关查询后,我也没有收到问题。

我正在使用以下概念: 1.共享实例

+ (WSHelper *)sharedInstance
{
    static WSHelper *appInstance = nil;
    if (nil == appInstance)
    {
        appInstance  = [[super allocWithZone:NULL] init];
    }
    return appInstance;
}

2。 MBProgressHUD

+ (void)showWaitIndicator:(UIViewController*)parentView
{
    if(![AppGlobals sharedInstance].HUD)
        [AppGlobals sharedInstance].HUD = [[MBProgressHUD alloc] initWithWindow:((AppDelegate *)[UIApplication sharedApplication].delegate).window];
    [((AppDelegate *)[UIApplication sharedApplication].delegate).window addSubview:[AppGlobals sharedInstance].HUD];
    [AppGlobals sharedInstance].HUD.labelText = @"Please Wait...";
    [[AppGlobals sharedInstance].HUD show:TRUE];
}

请帮帮我......

1 个答案:

答案 0 :(得分:0)

如果应用中的对象尝试访问已从内存中释放的另一个对象,则应用程序可能会崩溃。您需要检查所有对象的范围。尝试使用“Analyzer”来了解这一点。

很高兴有关于您的问题的更多信息:

if (nil == appInstance)替换为if(appInstance == nil)