app receives Memory Warning

Discussion in 'iOS Programming' started by sujithkrishnan, Jul 18, 2008.

  1. sujithkrishnan macrumors 6502

    May 9, 2008
    Hi all..

    In my app, the applicationReceivedMemoryWarning is getting called??

    how to trace out the origin / who is responsible to call, which line in code ???

    Plzzzzzz help.....
  2. SwampThingTom macrumors member

    Jul 12, 2008
    Fairfax, VA
    The Instruments tool is a great way to track down memory leaks. The "Instruments User Guide" in the Dev Center describes how to use it. Very easy and *very* useful.

  3. Enuratique macrumors 6502

    Apr 28, 2008
    It's called by the iPhone OS when it realizes it's about to run out of memory. There is no singular place to find out who's calling it. The intent of that method being called is to try and release any non-essential allocated memory to prevent a force-quit of your app. Chances are, however, you have a memory leak that needs plugging.
  4. sujithkrishnan thread starter macrumors 6502

    May 9, 2008
    But my app is taking a max of 2.75MB (highest peak shown in INSTRUMENTS)...
    I read that around 24MB is available as heap space...

    Is the above method(AppRecievedMemoryWarning) get called at those lines, where alloc /copy occurs??
  5. Enuratique macrumors 6502

    Apr 28, 2008
    How long is your app running before it gets the memory warning? Does Instruments say you still have leaks? Is Instruments collecting data throughout the life of the program (I had a weird case where Instruments would stop collecting data after my app's initialization phase). Could you possibly take a screenshot of Instruments when the memory warning happens?

    Also, the "peak" memory may be a misleading thing to look at. Take for example Instruments running my app.


    Note how the peak is less than total memory consumed over the life of the application. It's possible you have a thread that Instruments isn't measuring so any leaks in that thread are going undetected and thus causing the low memory warning. If that overall bytes column is continuously growing (even after initialization has completed) and you're not doing anything in the application - then I think that's a telltale sign you have a leak somewhere. I'd be curious to know what the overall bytes value is when you receive the low memory warning.
  6. receiptsondisk macrumors newbie

    Jan 17, 2009
    low memory warnings

    add NSLog messages to your didReceiveMemoryWarning method
  7. CommanderData macrumors regular

    Dec 1, 2007
    You're a few months late to that party ;)

Share This Page