0 votes

I'm have a problem with my game keeps increasing in memory usage, so i had to take actions to fix that

I try to free an object once it passes certain cordinates:

if get_pos().x >= 750 or get_pos().x <= -10:
     free()

i used a timer to instance this object in the main game scene every time the timer runs out but when the object fulfills the condition of the x cordinate reaching 750 or above (or -10 and below), instead of just the object being freed, the whole game just closes without an error

asked Apr 26, 2018 in Engine by Dava (115 points)
retagged Apr 26, 2018 by Dava

Try queue_free() instead of free(). The former waits until it's safe (more or less) to remove the node.

I tried that, but it doesn't seem to help free up memory, as the timer spawns new objects, the memory usage just increases and never reduces

Are you using Godot 2 or Godot 3? If you are using Godot 3, try using just position rather than get_pos(). I am not sure if get_pos() exists or is deprecated in Godot 3 and it might be the problem.

I'm using Godot 2

then, try to find a node which is created but not added to scene.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.