Search Instagram Twitter Facebook Spotify Grid Tag Date Folder Chat Pencil

Memory Leak Bug

For about the past week, there had been this really annoying bug – whenever the game was running on the PS4 devkit or my laptop, it would crash after about 5 minutes. What made this extra annoying was that I could’t replicate the issue on my desktop.

Talking to David, we determined it was a memory leak of sorts.

I pulled up the Unity Profiler, which has a section to look at current memory.

I saw that my material count was increasing by the thousands every frame. Within about 3 minutes, it was already at 70K and still increasing. This seemed quite strange to me.

As it turns out, in one of my scripts Update() function, I was calling Renderer.Material every frame, which as a result was creating new instances of material, hence the leak.

After I commented out the line responsible for this (don’t even remember what it was supposed to do in the first place), the game no longer crashed.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.