Search Unity

Out of memory

Discussion in 'Windows' started by Qbit86, Dec 25, 2013.

  1. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    Hello!

    The game suffers from lack of memory on Nokia Lumia 520, how can I fix it?

    I'm porting 3D shooter from iOS and Android to WP8. And I constantly encounter crashes due to System.OutOfMemoryException in managed code or C++ exceptions from UnityPlayer.dll (“Could not allocate memory: System out of memory!” in MemoryManager.cpp Line: 793), especially while loading new scene.

    I know that Lumia 520 is not that powerful; it has only 512 Mb RAM; 180 Mb of it is available to application (taking into account `ID_FUNCCAP_EXTEND_MEM`). However the same game feels quite playable on less powerfull iPod Touch 4 (256 Mb RAM); even more so on iOS and Android devices with 512 Mb. Moreover more sophisticated Angry Bots also look good enough on Lumia 520.

    Tried to cut off some meshes, lightmaps size, etc, it did help but very slightly. Debugging and profiling makes things even worse. Which ways should I try; maybe, some WP8 specific things? I've read some general articles like this , but not in the Unity context.

    Another question: how can I use Visual Studio Memory Profiler? The only available option is Execution (CPU) Profiler.

    Environment:
    Windows Pro 8.1 64-bit
    Unity Pro 4.3.1f1
    Microsoft Visual Studio Express 2012 for Windows Phone (provided with Windows Phone SDK 8.0)
    Nokia Lumia 520


    Any help would be very much appreciated!
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    Hello.

    As it currently stands, windows phone 8 games use more memory than their Android and iOS counterparts. We're working hard to fix it, but until we do, you will have to have other means to workaround the memory usage.

    The profiler: did you try actually using Unity memory profiler? Detailed view does not work due to it depending on Mono, however, simple view can tell you where the memory is used.

    Furthermore, memory profiler being unavailable to unity apps on Visual Studio is a visual studio bug. To workaround that, you'll have to edit <yourProject>.csproj file and replace reference instances like this:

    Code (csharp):
    1.  
    2. <ItemGroup>
    3.     <Reference Include="BridgeInterface">
    4.         <HintPath>..\Players\$(Platform)\$(Configuration)\BridgeInterface.winmd</HintPath>
    5.     </Reference>
    6.     ...
    7. </ItemGroup>
    8.  
    To this:

    Code (csharp):
    1.  
    2. <ItemGroup>
    3.     <_ExplicitReference Include="..\Players\$(Platform)\Release\BridgeInterface.winmd" />
    4.     <_ExplicitReference Include="..\Players\$(Platform)\Release\UnityEngineDelegates.winmd" />
    5.     <_ExplicitReference Include="..\Players\$(Platform)\Release\UnityEngineProxy.dll" />
    6.     <_ExplicitReference Include="..\Players\$(Platform)\Release\UnityPlayer.winmd" />
    7.     <_ExplicitReference Include="..\Players\$(Platform)\Release\WinRTBridge.dll" />
    8. </ItemGroup>
    9.  
    This should enable the profiler in Visual Studio, but I am not sure whether it will help you as it will show all of the internal Unity stuff as well which you have no control over.
     
  3. PrettyFlyGames

    PrettyFlyGames

    Joined:
    Aug 30, 2012
    Posts:
    74
    Hi!

    I had a similar issue and instead of manually changing all the textures I lowered to quality settings to the lowest possible. This will reduce texture size for you.

    To figure out when I hit the memory limit I used a Lumia 920 instead as the app would just stop when profiling on the 520.

     
  4. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,822
    Also try streaming audio from disk instead of loading into memory.

    Set this for the import settings on each audio file.
     
  5. koblykdmitry

    koblykdmitry

    Joined:
    Jan 17, 2014
    Posts:
    14
    Hi,

    Qbit86, do you have suggestions how to reduce memory usage on lumia 520? I have the same problems with memory. Maybe you can share some optimizations?

    Thanks.
     
  6. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    Thank you, this works in “Visual Studio Express 2012 for Windows Phone”*— memory profiler becomes available. Could you fix an MSBuild script generation so that .csproj file contains these explicit references out of the box?
     
  7. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    It will be fixed in 4.5.
     
  8. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    Unfortunately, “Analyzing the data” stops after end of session with message “Parsing of log file failed”; googling doesn't help. Have anyone faced this problem?

    ProfilerLog_ says:
     
    Last edited: May 14, 2014
  9. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    In my personal experience this happens when you log the session for longer than VS can manage to analyze - I'm not entirely sure about the threshold, though.
     
  10. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    I've tried this only with free “VS Express 2012 for Windows Phone”. Have you tried profiling with “VS Pro 2013”?
     
  11. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    Yes. There aren't many differences between the two. It handles it up to a minute of data just fine. On bigger games it any longer than that usually makes it not be able to finish up the report.
     
  12. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    302
    Any news on the issues with memory usage? Seeing our apps closing in background constantly, and it's by no means heavy apps... Running Unity 4.5.5 atm and can't update to later.

    Thanks!
     
  13. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    This is an old, old thread. I'm fairly certain that today we're very close to what equivalent Android or iOS player is using. What kind of issues are you facing and what kind of phone are you testing on?
     
  14. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    302
    In what version of Unity are you refering to when saying: "very close to what Android or iOS player is using"?

    We have crashes reported from the Windows dashboard, see examples below:
    Code (CSharp):
    1.  
    2. BAD_DUMP_MISSING_MEMORY_STACK_OVERFLOW_DATA_MISSING_CLR_METADATA_AVRF_bad_dump!missing_teb
    3.  
    4. BAD_DUMP_MISSING_MEMORY_ZEROED_STACK_bad_dump!missing_teb
    5.  
    6. BAD_DUMP_MISSING_MEMORY_bad_dump!missing_teb
    7.  
    8. APPLICATION_FAULT_OOM_OOM_template.exe!out_of_memory
    9.  
    10. BAD_DUMP_MISSING_MEMORY_SOFTWARE_NX_FAULT_MISSING_CLR_METADATA_NULL_IP_bad_dump!missing_teb
    11.  
    12.  
    And then there's some more similar or completely different errors.
     
  15. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    I was referring to Unity 4.6.x and 5.x - TBH 4.5.x is so old I can't really remember how the memory was back then exactly.

    Either way, just because it's close to Android or iOS player, it doesn't mean that you will not crash when you reach the memory limit. Remember, these limits are different when it comes to different OSs and phones. You probably have to test your application on a phone with as much memory as the one that has crashes recorded.