0 votes

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.

in Engine by (306 points)

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. :p

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

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.

1 Answer

+1 vote
Best answer

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.

by (306 points)

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 :P

Shouldn't queue_free() be sufficient?

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.

@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.

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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.