Strange Memory Warnings

I’ve started to get memory related crashes with iPhone Unity 1.6 so I’ve implemented the recommended use of a level loader. Essentially I have an empty level that accesses a static global with the next level to load. It works but I’m still getting memory crashes. So I enabled the internal profiler and from what I can see, the heap is reasonably sized so I’m not sure WHY I’m getting the memory warnings and sometimes being killed by the iPhone OS (it seems to happen that the iPhone kills the app almost randomly). It looks like this:

End Load File completely 1.410833 [the empty level]

iPhone Unity internal profiler stats:
cpu-player> min: 2.1 max: 402.3 avg: 27.8
cpu-ogles-drv> min: 0.0 max: 34.4 avg: 3.8
cpu-present> min: 1.2 max: 13.8 avg: 2.8
frametime> min: 30.6 max: 427.3 avg: 60.7
draw-call #> min: 0 max: 53 avg: 8 | batched: 36
tris #> min: 0 max: 27643 avg: 4583 | batched: 3950
verts #> min: 0 max: 30609 avg: 5050 | batched: 4502
player-detail> physx: 2.2 animation: 0.0 culling 0.4 skinning: 0.0 batching: 2.2 render: 5.8 fixed-update-count: 1 … 17
mono-scripts> update: 4.7 fixedUpdate: 0.2 coroutines: 3.0
mono-memory> used heap: 208896 allocated heap: 266240 max number of collections: 0 collection total duration: 0.0

[ two frames of stats deleted but they look pretty much like the one above ]

End Load File completely 12365.687000 [the real level I want]

WARNING → applicationDidReceiveMemoryWarning()
WARNING → applicationDidReceiveMemoryWarning()
WARNING → applicationDidReceiveMemoryWarning()
WARNING → applicationDidReceiveMemoryWarning()
iPhone Unity internal profiler stats:
cpu-player> min: 1.5 max: 21933.3 avg: 752.8
cpu-ogles-drv> min: 0.0 max: 223.9 avg: 11.9
cpu-present> min: 1.3 max: 19.8 avg: 3.9
frametime> min: 27.9 max: 22017.6 avg: 810.3
draw-call #> min: 0 max: 64 avg: 12 | batched: 15
tris #> min: 0 max: 7561 avg: 1489 | batched: 686
verts #> min: 0 max: 10866 avg: 2138 | batched: 1099
player-detail> physx: 15.2 animation: 0.0 culling 1.0 skinning: 0.1 batching: 0.1 render: 10.8 fixed-update-count: 1 … 17
mono-scripts> update: 3.2 fixedUpdate: 8.8 coroutines: 59.5
mono-memory> used heap: 266240 allocated heap: 266240 max number of collections: 0 collection total duration: 0.0

Does anyone have any idea why I would be getting such memory warnings with such a small heap ???

These warnings come from the xcode side and tell you that your app is using that much RAM that the device nearly ran out of memory.

After you receive these warnings you enter the area where basically any load of new media can get your application forcefully killed by the iphone (which will then show up as sigbus for signal “0”)

I understand the warnings are not from Unity. My question is why is unity using so much memory when according to its own statistics the applications needs are moderate.

Hi,
"WARNING → applicationDidReceiveMemoryWarning() " means your app is running out of RAM. Typically such warning is received when your application memory usage is crossing 35 MB on 1st gen devices (>100 MB on 3GS).
Top 3 causes for that:

  • application isn’t using stripping (advanced license feature) and application binary gets fat when using many .NET libraries.
  • application assets aren’t optimized, like textures aren’t PVRTC compressed.
  • there are just too many game objects instantiated at runtime.
1 Like

I am getting the same issue. I get worse and worse memory warning as the game progresses, yet I am not using more heap.

For example, earlier in my scene I got the following:

iPhone Unity internal profiler stats:
cpu-player> min: 8.7 max: 353.7 avg: 28.5
cpu-ogles-drv> min: 0.5 max: 8.1 avg: 5.2
cpu-present> min: 0.4 max: 0.4 avg: 0.4
frametime> min: 32.3 max: 34.3 avg: 33.3
draw-call #> min: 3 max: 20 avg: 16 | batched: 13
tris #> min: 38 max: 15778 avg: 12669 | batched: 76
verts #> min: 56 max: 6194 avg: 4973 | batched: 55
player-detail> physx: 0.6 animation: 2.1 culling 0.8 skinning: 2.0 batching: 0.0 render: 9.9 fixed-update-count: 1 … 2
mono-scripts> update: 1.4 fixedUpdate: 0.0 coroutines: 0.0
mono-memory> used heap: 700416 allocated heap: 860160 max number of collections: 0 collection total duration: 0.0

2011-05-18 12:58:00.093 unity_app[749:307] Received memory warning. Level=1
WARNING → applicationDidReceiveMemoryWarning()

Then later in the same scene…

iPhone Unity internal profiler stats:
cpu-player> min: 7.0 max: 361.6 avg: 30.2
cpu-ogles-drv> min: 6.1 max: 12.7 avg: 8.0
cpu-present> min: 0.4 max: 3.5 avg: 0.7
frametime> min: 32.1 max: 370.2 avg: 46.9
draw-call #> min: 12 max: 55 avg: 18 | batched: 3
tris #> min: 19717 max: 28608 avg: 21096 | batched: 1163
verts #> min: 18196 max: 21749 avg: 18817 | batched: 385
player-detail> physx: 4.0 animation: 0.2 culling 1.7 skinning: 0.2 batching: 0.2 render: 10.3 fixed-update-count: 1 … 12
mono-scripts> update: 10.5 fixedUpdate: 0.3 coroutines: 0.2
mono-memory> used heap: 720896 allocated heap: 860160 max number of collections: 0 collection total duration: 0.0

2011-05-18 13:01:00.882 unity_app[749:307] Received memory warning. Level=2
WARNING → applicationDidReceiveMemoryWarning()

Why would I be getting memory warnings when my heap usage remains fairly constant? :face_with_spiral_eyes:

Heap has nothing to do with your memory usage. Heap is only about raw allocated code memory.
The major part of your RAM usage is textures, meshes and audio and naturally the up to 15mb of raw binary program code if you don’t have stripping from iOS PRo

Reduce them or don’t target the lower level devices like pre 3GS where you have 30MB of RAM if you are lucky, more likely though like 25mb

Dreamora is spot on, the mono heap is NOT where your textures/sounds/music reside. To get the real picture of your overall memory usage, run the app through activity monitor in Xcode.