Memory Leak and Crashes

I’ve written a fairly large and complex game using only Global Variables and Global Objects. This was a requirement because of the nature of the game—everything has to be available at all times. There are between 100 and 200 Global Variables, and around 100 Global Objects. The whole game file is under 250MB. I’m using External Events, but there’s probably a couple thousand conditions and actions in this game. I’m dealing with random game crashes every few minutes on mobile and memory alerts on the computer after running for a long time. This leads me to believe there is a memory leak problem. I’m not sure how to track down the cause. I know Scene Variables are wiped from memory every time a new Scene is loaded. Is there a way to wipe Global Variables from memory and reload them as needed?

Note that GDevelop is running JavaScript, meaning that there is no such thing as deleting stuff from memory. JavaScript is garbage collected, so every now and then it will try to see what memory is not used anymore and free it, but this process is unpredictable and rare. If you are loading and deleting a lot of stuff (like constantly switching scenes), no wonder than you have memory issues as the unloading of the scene deletes a lot of data but not from memory until garbage collection triggers.

GDevelop and generated code is generally not very big, especially on mobile, if your apk is around 250mb maybe you have got way too big images and it doesn’t all fit into the GPUs vRAM, try to compress your images and make them smaller resolution maybe?

While I think it is not very likely that there is a memory leak in GDevelop’s code it is entirely possible, though knowing that there is one doesn’t make it easier to find it. If you find some way of replicating the memory leak issue consistently, please share your project and the setup so that we can analyze the game code with the development tool while the memory leak is happening.

1 Like

Thank you for the swift and detailed reply.

There is a wiki page in work in progress for optimize the projects.

1 Like