- Home /
So how much memory is my iOS game using?
I've got three numbers that don't match between XCode "Allocations", "Memory Monitor" and the new detailed view Unity Profiler.
Unity profile says I'm using 99MB of memory XCode Allocations says 131MB XCode Memory Monitor says 232MB
I'm guessing the latter is right, because I start getting allocation warnings when it goes above 250MB and am killed shortly afterwards (on an iPad2).
So how am I meant to work out what is using what? What do I multiply my Unity detailed profiler readings by to get an accurate picture?
I've tried multiplying Texture and Meshes by 2 - this gives 150MB, but clearly multiplying the whole thing by 2 wouldn't give me the reading of Memory Monitor.
What techniques can I use?
Details about the app:
Vuforia plugin
Scaleform plugin
Scene has around 8000 tris, 3 skinned mesh renderers, everything else static.
2 cameras (1 for reflection texture, this is a dressing room).
Interesting question. I can't say anything for sure, but this seems like a decent educated guess:
Unity Profiler sees only $$anonymous$$ono's allocations, not those made by the native engine code.
XCode Allocations sees both script and engine allocations, but reports them based on the runtime (virtual memory, allocated in bytes).
XCode $$anonymous$$emory $$anonymous$$onitor reports allocation based on the operating system's paging (physical memory, allocated in larger blocks/segments/pages).
Is it possible that your program is suffering from memory fragmentation?
It could also be that each report is including an additional layer of infrastructure overhead, but if that's the case then it's surprising that the last number is so much bigger.
Good advice, thanks. I should look at that fragmentation (though why it would be happening I don't know) - the virtual memory size (which is apparently memory span on the device) is almost 490$$anonymous$$B. The $$anonymous$$ono $$anonymous$$emory size is around 50$$anonymous$$B, so it appears that the other stuff is something to do with:
Resources/Assets
Scaleform
Vuforia
So I've just tried running Scaleform on its own and it's 25$$anonymous$$B (in Instruments) Vuforia seems to be about 30$$anonymous$$B (in Instruments).
There's still a huge difference, it's very confusing!
It certainly appears that Unity is reporting the texture memory it uses, when actually the phone needs to allocate that again to be shared with the GPU.
Bear in $$anonymous$$d that you'll get a memory warning when iOS starts to notice memory is short. You might find that all the other apps that are still in the background are using memory. So, try rebooting the device and see if you get memory warnings. iPad2 has 512$$anonymous$$ of memory and I guess your device has half of that memory in use by other apps. (I'm not a massive expert on iOS memory. Will flag this question up to developers.)
Actually it's been tried on multiple test devices (iPhone 4, 4S, iPad 2, iPad $$anonymous$$ini) which are rebooted between installations, so it appears (and I've read somewhere) that iOS isn't very happy about any app using more than half of the memory.
It's just hard to work out what I should be trying to save memory on, because I've got more than double the usage from the only detailed view I have access to :S
I'm presu$$anonymous$$g the $$anonymous$$ono memory usage is accurate (because surely it can be), so I need to work out how come I'm using more than 200$$anonymous$$B when Unity says I'm using 60$$anonymous$$B in assets.
Answer by kromenak · May 11, 2013 at 08:14 PM
I've spent a bit of time looking into this in the past; the Unity profiler provides memory info on assets loaded into the game, but unfortunately it isn't a complete picture of memory being used.
The XCode memory monitor is certainly the most accurate value, and also the one that really matters; it is an accurate indicator of when you will start seeing memory warning and ultimately an app crash.
Also, FWIW, I'm under the impression that there are three areas in Unity that use memory: managed heap, native heap, and the app code. Managed heap is stuff allocated in script, native heap is mainly assets, and app code is all the code and DLLs. The app code can actually bite you pretty hard. Unity by itself is a good chunk of memory (8-14MB I think) and then any DLLs or code associated with Vuforia or Scaleform might be pretty heavy as well. App code is pretty much always in memory; loaded up on app start and stays until it closes.
Anyway, as I said, I've spent some time working through Unity's memory puzzle, but I'm certainly not an expert - so if any of the above sounds wrong, please correct me!
Your answer
![](https://koobas.hobune.stream/wayback/20220613101951im_/https://answers.unity.com/themes/thub/images/avi.jpg)