Freeing an object "frees the game"

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Dava

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:

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

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

Diet Estus | 2018-04-26 20:04

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

Dava | 2018-04-26 20:12

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.

Diet Estus | 2018-04-26 20:15

I’m using Godot 2

Dava | 2018-04-26 20:16

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

volzhs | 2018-04-27 16:25