Out of memory

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!

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 .csproj file and replace reference instances like this:

<ItemGroup>
    <Reference Include="BridgeInterface">
        <HintPath>..\Players\$(Platform)\$(Configuration)\BridgeInterface.winmd</HintPath>
    </Reference>
    ...
</ItemGroup>

To this:

<ItemGroup>
    <_ExplicitReference Include="..\Players\$(Platform)\Release\BridgeInterface.winmd" />
    <_ExplicitReference Include="..\Players\$(Platform)\Release\UnityEngineDelegates.winmd" />
    <_ExplicitReference Include="..\Players\$(Platform)\Release\UnityEngineProxy.dll" />
    <_ExplicitReference Include="..\Players\$(Platform)\Release\UnityPlayer.winmd" />
    <_ExplicitReference Include="..\Players\$(Platform)\Release\WinRTBridge.dll" />
</ItemGroup>

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.

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.

Also try streaming audio from disk instead of loading into memory.

Set this for the import settings on each audio file.

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.

[quote]
Furthermore, memory profiler being unavailable to unity apps on Visual Studio is a visual studio bug. To workaround that, you'll have to edit .csproj file and replace reference instances like this...
This should enable the profiler in Visual Studio...
[/quote]

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?

It will be fixed in 4.5.

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:

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.

I've tried this only with free “VS Express 2012 for Windows Phone”. Have you tried profiling with “VS Pro 2013”?

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.

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!

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?

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:

BAD_DUMP_MISSING_MEMORY_STACK_OVERFLOW_DATA_MISSING_CLR_METADATA_AVRF_bad_dump!missing_teb

BAD_DUMP_MISSING_MEMORY_ZEROED_STACK_bad_dump!missing_teb

BAD_DUMP_MISSING_MEMORY_bad_dump!missing_teb

APPLICATION_FAULT_OOM_OOM_template.exe!out_of_memory

BAD_DUMP_MISSING_MEMORY_SOFTWARE_NX_FAULT_MISSING_CLR_METADATA_NULL_IP_bad_dump!missing_teb

And then there's some more similar or completely different errors.

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.