Memory Leak?

Hey guys, I've got a situation going on that feels kinda funny to me and I just want to understand what's happening.

I've got a game that's basically an endless runner going downwards. It's got a basic world generation chunk system going on that creates chunks of map about 900 pixels in height and the width of the screen and destroys anything that goes above the top of the screen. The chunks of map are also entirely populated with blocks that are 16x16 in size (this is a probly a little silly, but it's just a prototype right now). The speed of the player also gradually increases as the game goes on.

As the speed gets higher and higher, the FPS drops (not dramatically, but just gradually drops with the increase in speed). I kind of expected this, I mean, at the very least I wasn't super surprised, but when I open task manager and monitor the game as it goes on, the memory use also gradually increases (not fast, just very slowly gets higher and higher). This seems a little funny to me, because it really should only be dealing with like three, four at the very max, chunks. Eventually at a vspeed of around 20-30 the game gets into an unplayable state FPS wise (memory wise it's using about 60-70 megs and CPU usage is maybe 15% or so).

So I did a little exploring. I added in a command that entirely stops the players speed and any world generation, expecting everything to stabilise when I hit the appropriate stop button. The CPU and FPS recover to normal, but the memory usage stays exactly where it was. So I added in some keyboard commands so I can move the view around to make sure that my spawned blocks are being destroyed and not clogging up the memory, and when I move the view around, there's no blocks apart from the current chunk the player is in.

I'm just curious as to what could possibly be causing the memory to not drop back down to normal when everything else does.

My block deletion code is in Begin Step and goes thusly:
Code:
if (stop == false) {
with (all) {
    if (y < view_yview[0]-15) {
        instance_destroy();
    }
}
//instance_deactivate_region(view_xview[0]-50,view_yview[0]-50,view_wview[0]+100,view_hview[0]+100,false,true);
instance_deactivate_all(true);
instance_activate_region(view_xview[0]-50,view_yview[0]-50,view_wview[0]+100,view_hview[0]+100,true);
}
The commented out section is part of me trying to figure out if anything was wrong and stop is only true when I hit space.

I've also put a check in the blocks Step Event to destroy the blocks if y < view_yview[0]. As I said, when I look around, I can't see anything other than the current chunk, but it seems as though everything being created is still stored somewhere in the memory.

Any help would be greatly appreciated.
 

Phil Strahl

Member
I am not a 100% certain how instance_deactivate() behaves, but could it be possible that deactivated instances just ignore the instance_destroy() call?

EDIT: How's your usage of data structures, files, buffers, and surfaces? Usually memory leaks happen with those..
 

FrostyCat

Redemption Seeker
You have a dead zone between view_yview[0]-15 and view_yview[0]-50 where instances would stay deactivated but never destroyed. That is a serious memory leak. Either expand your activation zone upwards, or move down the kill line.
 
Ah, ok Frosty, my thought process was that I would destroy anything above -15 pixels of the view and then deactivate the region outside of -50 all around the view as a kind of buffer (i.e. if on the off chance something wasn't being destroyed at -15, it would at least get deactivated at -50). I've commented out all the deactivation code and the memory problem stays precisely the same.

And Phil, the prototype is super basic. No data structures, no surfaces, no nothing. Basically just a player object, a ground object and an object spawner with movement and destruction. So I think it has to be something to do with the ground objects being spawned...

Here's the .gmz if anyone wants to look at it. I'm still really confused as to what it could be.

EDIT: Btw, I've just realised I have destruction code in both the Begin Step of my player object AND the Step Event of the ground object (removing this doesn't fix the problem, I've just been trying various things to see if I could fix it somewhere). Just pointing it out if someone wants to mess with the .gmz.

https://www.dropbox.com/s/4ighoq20zg1k8kc/Fossil Hunters.gmz?dl=0
 
Last edited:
T

The Shatner

Guest
Hey RefresherTowel,
One of the main problems that may cause memory leaks is the excessive amount of graphics being processed at the same time, even if they are out of the room screen. Maybe if you have too many graphics, the game starts to have difficulty to get data from multiple texture pages and you end up in trouble.
The advices from a help page here helped me a lot while making my game (in the signature below, in case you want to check it out;)), and I had more than 30% increase in the FPS and overall processing.
Here goes the link: http://www.yoyogames.com/blog/23
Try some of the tips there and give us some feedback.
Besides, which platform are you developing to?
 
U

umetnik

Guest
There is a problem in obj_drill, step event, line 30. Check "y >= global.length/2" should be something like "y >= global.length - 350", or something similar. Currently more obj_ground instances are being generated than destroyed (thus memory leak). You can check it for example in script generate_earth by outputting number of instances , e.g. "show_debug_message("COUNT: " + string(instance_number(obj_ground)));".
 
That was it umetnik, thank you =). Stabilised the loss. I should've checked the number of obj_ground objects being created in hindsight, that is an obvious way to make sure my spawning code was functioning correctly.

Thanks for link Shatner, the info is great, but my project is super bare bones right now and doesn't use anything that it could be useful for yet. As for the platform, I'm thinking of Android/IOS right now, so optimisation will be key.
 
Top