Large number of objects not cleaned up properly

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By supaiku
:warning: Old Version Published before Godot 3 was released.

Hi,

I ported a fairly large JavaScript codebase to GDScript. With JavaScript I never bothered, because the GC took care of everything.

Now in Godot I noticed, that only a fraction of all allocated objects are released. The Debugger/Monitor initially says 1000 objects. When I enter a certain scene it goes up by another 1k. Upon leave it should go down by 1k, but instead only removes like 200. I can repeat this step endlessly and make my game eat memory like crazy.

All my objects are References. I have no clue how I go and find out which references are being kept alive in memory. Though, that would help me enormously.

I’m also sure that I set all refs to null, before leaving the scene. So… how can I find out what keeps living in memory?

Thanks in advance.

Uh… Nevermind. I missed a line and it has never been cleaned up at all. Now I’m down to 18 remnants. Questions stays somewhat relevant… I’m curious how to identify them. :stuck_out_tongue:

supaiku | 2016-08-02 00:30

What is the inverse function of queue_free() ?
I need to reinstance my parent so that I can add all its children later

Pedro Karut Gimenez | 2016-08-03 18:24

There’s no such thing as an inverse function of queue_free. This method tells the engine to destroy and erase permanently the node. Once you call it, the node is dead, gone forever.
If you want to reuse a node, don’t free it. Just remove it from its parent. Then add it again when you need it back.

Gokudomatic2 | 2016-08-04 16:01

:bust_in_silhouette: Reply From: supaiku

Hah. I finally tracked the last ones down. I don’t know why, but in one of my scenes I created a variable tooltipInstance

const MyTooltip = preload("MyTooltip.tscn")
...
var tooltipInstance = MyTooltip.instance()

which caused the leak. I queue_free’d the parent, but somehow this one kept lingering around. So I added a

tooltipInstance.free()

and now everything is cleaned up properly.

Wait, so to remove scenes, we must use .free() and queue_free()? Just to clarify as I’m running a ton of added tooltip scenes too :stuck_out_tongue:

Shouldn’t queue_free() be sufficient?

wombatTurkey | 2016-08-02 19:55

Hi,

yes you are right. Normally, queue_free is enough… But I didn’t always assign a parent to my instances. That’s why they weren’t always freed.

supaiku | 2016-08-02 22:15

@supalku thanks

I’ll re-check my code too, I usually just instance the scene and add it as a child… I havn’t found any memoryleaks though yet (not even sure how to check lol) – but I do queue_free() them when switching levels, etc.

wombatTurkey | 2016-08-03 02:04