0

My application is crashing many times due to receive memory warning, even it is showing allocated live bytes as 7-8 MB only as shown in screenshot. enter image description here I'm not getting the issue even after searching all related queries.

i'm using following concepts: 1. shared instance

+ (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];
}

Please help me out...

Loquatious
  • 1,791
  • 12
  • 21
  • You got a pretty huge overall. iOS can force-close the app, if the overall exceeds 20% device memory capacity or when total overhead grows too fast. I'd also suggest you use another method of creating a singleton, like this - http://stackoverflow.com/questions/5720029/create-singleton-using-gcds-dispatch-once-in-objective-c – Kyr Dunenkoff Aug 05 '13 at 05:47
  • @KyrDunenkoff Thnx for you reply. I'm using iPad-3 device. Can you please tell me how much max it'll allow for overall bytes? – Loquatious Aug 05 '13 at 05:52
  • @KyrDunenkoff I'm just going through login >> listing >> logout >> login >> listing >> logout repeatedly for 7-10 times. If i'm popping to rootViewController it's not releasing unloaded viewcontrollers... – Loquatious Aug 05 '13 at 06:10
  • If it's not releasing VCs on pop you probably got a retain cycle somewhere, meaning some object (like your sharedInstance) is strong-referencing your VCs. – Kyr Dunenkoff Aug 05 '13 at 07:27
  • @KyrDunenkoff yes, this might be the reason. Can you please explain how can i overcome this issue? – Loquatious Aug 05 '13 at 07:46
  • @KyrDunenkoff property (weak, nonatomic) id target; After giving like this also not releasing. – Loquatious Aug 05 '13 at 07:48

1 Answers1

0

Application may crash if an object in your app tries to access another object which is already released from memory. You need to check the scope of all your objects. Try "Analyser" instead to know this.

Nice for having more information on your question :

Replace if (nil == appInstance) with if(appInstance == nil).

CodenameLambda1
  • 1,299
  • 7
  • 17
  • OP specifically states that he is receiving memory warning. You are talking about EXC_BAD_ACCESS kind of errors. – Krishnabhadra Aug 05 '13 at 05:37
  • Where are you seeing memory warning exactly ? Also, check the edit on my answer. – CodenameLambda1 Aug 05 '13 at 05:45
  • Anywhere in app. Replace if (nil == appInstance) with if(appInstance == nil) makes memory issues? – Loquatious Aug 05 '13 at 05:49
  • I am trying to make you write proper code. So that you may not run into any other errors. Plus, I require you to check the project with "Analyser" to check if along with memory warnings there is no other simultaneous crash caused in the next cycle which remains hidden. Instruments is a high level software and it sometimes does not show all errors, if the app quits on first, but the reason might be the second but it just happening at the same instance. Further, it looks like the object that you're trying to allocate isn't getting enough memory while allocation & so it crashes only in 6-7 MB. – CodenameLambda1 Aug 05 '13 at 05:56
  • @CodenameLambda1 I'm just going through login >> listing >> logout >> login >> listing >> logout repeatedly for 7-10 times. If i'm popping to rootViewController it's not releasing unloaded viewcontrollers... – Loquatious Aug 05 '13 at 06:09
  • ARC will only release an object when the object is not referenced by any other object. So, it seems like the controller you're popping is still being referenced somewhere. You can do one thing, try to set nil to any WSHelper instance you use in your controller, before you pop it. – CodenameLambda1 Aug 05 '13 at 06:17
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/34815/discussion-between-simha-ic-and-codenamelambda1) – Loquatious Aug 05 '13 at 06:40