Search Unity

When game goes to background and returns, memory usage drops by 30MB, why?

Discussion in 'iOS and tvOS' started by Velvety, May 27, 2014.

  1. Velvety

    Velvety

    Joined:
    May 4, 2009
    Posts:
    153
    Hi,

    We are trying to reduce the memory footprint of our iOS game. We are currently doing a fair bit of processing at the start of a scene to load in various asset bundles, use parts of them, and unload the unused parts of them. We are unloading unused assets and calling the garbage collector as we do this processing.

    In general this seems to be working, but we've noticed something odd. If we suspend the app to the background and then return to it, the XCode memory profiler shows that our in-game memory is reduced by another 30Mb! Clearly sending our game to the background triggers some kind of garbage collection that is not being triggered in-game. We would love to be able to manually trigger this process in code after we first load a scene to get that 30Mb of memory savings, but we can't figure out how.

    Does anyone know why we are seeing this savings of memory after suspending the game? Does anyone know how we can replicate it with specific code?

    Thanks!
     
  2. unimechanic

    unimechanic

    Joined:
    Jan 9, 2013
    Posts:
    155
    iOS apps have "clean memory" that can be recreated by the system, this memory can be reclaimed by iOS when the app is suspended. In contrast the system can't unload "dirty memory", unless it reaches a certain limit and the app is terminated. You can use Intruments VM Tracker to have a better understanding of the memory usage.
     
  3. Velvety

    Velvety

    Joined:
    May 4, 2009
    Posts:
    153
    Ok, that makes sense. Thanks for the reply!