Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

iOS crash problem: Received memory warning

Discussion in 'iOS and tvOS' started by moh05, Aug 4, 2016.

  1. moh05

    moh05

    Joined:
    Nov 26, 2015
    Posts:
    65
    Hello guys,

    I am developing a card game. I received the following warning from Xcode:

    Received memory warning... WARNING -> applicationDidReceiveMemoryWarning()

    When the game changes scene from Main Menu to the Game Level, it crashes. It doesn't happen in all phones of the same model though ( tried with different iPhone 5 devices, I get the message in some of them).

    What might be the problem? How can I solve it?

    Thank you
     
  2. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    When you say crash do you mean that the OS is simply killing your app, or is an actual crash (which may have nothing to do with memory usage)?

    I'm no expert but you you could try using the Xcode tools to track memory usage, or use the Unity memory profiler. You could try unloading unused assets?
     
    moh05 likes this.
  3. moh05

    moh05

    Joined:
    Nov 26, 2015
    Posts:
    65
    yeah OS kills the app. I think unloading unsused assets will do it right? I mean why it crashes on some devices and others not? ( taking into consideration they are the same device type)
     
  4. r-pedra

    r-pedra

    Joined:
    Dec 4, 2015
    Posts:
    104
    Memory warning happens when iOS detect that it runs low on memory. It informs applications that if no one clean his s**t, it will starts to kill apps to free up some memory.

    Why it happens on some devices and not on others that have the same hardware? Because every phone is different. Each user installs his own apps, some user install apps with low memory footprint. But other install big apps with high memory footprint.
    iOS can choose to kill your app or not, he choose one app that take lots of memory and kill it, even if it's currently running.

    So you better clean your garbages if you don't want iOS to be your mother and clean your garbage in a very angry style ahah
     
    moh05 likes this.
  5. Crichton333

    Crichton333

    Joined:
    May 4, 2014
    Posts:
    113
    Are you trying this on a regular iPhone 5 thats 32bit only or on the iPhone 5S thats 64 bit.
     
  6. moh05

    moh05

    Joined:
    Nov 26, 2015
    Posts:
    65
    Thank you, so any tips on garbage collection? Maybe I need to unload resources from main menu while loading the main level game?
     
  7. moh05

    moh05

    Joined:
    Nov 26, 2015
    Posts:
    65
    I didnt check that, what would be the difference?
     
  8. r-pedra

    r-pedra

    Joined:
    Dec 4, 2015
    Posts:
    104
    We have made some nice discovers recently about memory.
    We found that any prefab linked in the scene(even if you never load it), loads everything it contains in memory. It includes textures. If you have a prefab with many textures, it will load textures into memory.
    If you instantiate the prefab, you will still all in memory.

    Now, if you replace your prefabs with a local AssetBundle system, objects will be loaded in memory only when you instantiate them, and will be destroyed when you destroy your GameObject.

    We reduced the memory load with that. (on Main Screen of our game, before: 40K object in memory, after: 19K /// Before: 140Mb of Texture, after= 100Mb of Texture).

    Remember to compress your textures.
    For big atlases with alpha, we used a shader that combine a RGB atlas with a copy of our atlas in Alpha 8 format.
    A 16Mb 2Kx2K atlas now weight 6Mb(Atlas+Alpha Mask), before, it was 16Mb with no compression.

    Definitely, if you make these 2 things, will be able to perfectly control what is in memory and what is not in memory, and remove from memory useless objects when you know that your memory footprint is high.