Child nodes not freeing after calling queue_free

Version 4.4

I have been trying to free all of the nodes in the scene for each of my enemies when they die however when I use queue_free() on the root node it is not freeing any of the raycasts or shapecasts from the node.
I have tried using free() and still the children do not get freed. For now this does not affect my game however I have concerns about it causing performance issues in the future.
I can tell that it isn’t freeing them as if I turn on visible collision shapes they do not disappear and still track collisions.

Hi!

I’ve never heard of queue_free nor free not working if called correctly, so it seems like a very weird issue. Are you sure the queue_free/free function is actually called, and on the right nodes?
If that doesn’t help, could you share your code?

If I recall correctly, these things are reference counted, and the *free() functions decrement the refcount rather than explicitly delete. It sounds like your things are still referenced somewhere. Maybe some sort of cyclic reference?

I believe the function is called as other parts of the script that get called when the enemy dies are triggered I will send the code later

What would be an example of a cyclic reference?

Object A has a reference to object B, which has a reference to object A. So, A can’t be deleted because B is still looking at it, and B can’t be deleted because A is still looking at it. This is a classical weakness of refcounting systems, and is usually solved either by “weak” references (that is, references that are allowed to fail and don’t keep the thing they’re looking at alive), or by manual management (that is, manually nulling internal references before freeing things).

Thank you that does make sense I will test if this is the issue.

Nodes (assuming that you are talking about ray-cast and shape-cast nodes) are not ref-counted but need to be explicitly freed. It doesn’t matter how many references there are to a node - when you free it all references to it become invalid. Freeing a node should also free all its children.
So it seems that there is something else going on. As @sixrobin mentions, are you sure you are actually freeing the node? Can you share your code and your node structure?

1 Like

I have figured out the issue it was a mistake on my end. The freeing was meant to happen after a death animation however the I switched the animations visibility to false which means that the queue_free was never triggered as it relies on the animation finishing when it never actually finished.

Thank you for all the help this is my first time using this forum and I was surprised on the speed and quality of response! Thanks again

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.