- Home /
How to reduce memory usage?
Hi, I'm working on 2D game using Unity 4. Last time after adding new animations and textures my game stopped working on most of android devices. For now, I know it works only on Samsung Galaxy and maybe on other fancy smartphones but I'm not able to check it. When I run it on desktop it uses almost 2GB of memory during loading and 1GB during gameplay. This is really suprising because my game is pretty simple. Not much code, few animations and sprites + Physics2D.
So my question is how this high memory usage is possible? What am I missing? What can I do to reduce memory usage? I know I can compress the textures and animations but still I can't believe that 15MB app uses 2GB of memory. I just started my work with Unity and for now I'm out of ideas. Any help?
Are you using any audio? some of the settings for audio files can have a huge overhead.
How big are your textures? You can usually compress textures down quite a bit in the unity import options before it shows.
Too many draw calls can also bog down performance. Packing tons of stuff into sprite sheets can really save on draw calls, but of course the larger the sheet, the more texture memory it takes up.
$$anonymous$$ake sure you limit your OnGUI calls- usually you can keep objects with scripts that call onGUI deactivated until you need them.
Avoid instantiating/destroying lots of things. Use the Object Pool pattern for things like that ins$$anonymous$$d.
If none of the above help, could you post a screenshot of the stats tab from in Unity with your game running?
Or even better, deactivate things one at a time and see if you can't nail down which objects are causing the biggest draw on your performance.
But the problem is that I get big memory usage when Unity splash screen shows and then app just shuts down.
I don't use any audio for now.
if you have Unity Pro, use the profiler to see what is using the most memory.
It could be almost anything...
Problems started after adding animations so I'll try reduce textures size and pack animation frames into sprite sheets.
I don't have Unity Pro for now.
Answer by dsada · Jun 09, 2014 at 09:57 PM
when i had this problem. The problem was i created a lot of new object in Update(), OnGUI() functions. Like textures, GUIStyles, etc.. As it seems, GC cant handle that. Hope this helps.
But of you have PRO the profiler can easily tell you where the problem is
Your answer
Follow this Question
Related Questions
WEBGL Memory Usage Problem 1 Answer
Is this memory usage too much for a mobile game? 1 Answer
Question About Camera's, Canvases and Memory 0 Answers
Reduce GPU Memory usage from textures 1 Answer
Reducing memory in voxel game 0 Answers