About queue_free()

I have a question about timing of the queue_free() function. Is the object freed immediately or is it queued to be freed at the earliest convenience?

I ask because in the Lightning script the queue_free() function call is in the for loop. I would put it after the loop. My reasoning is that if the lightning collides with the terrain and bunny at the same time and the get_overlapping_bodies() call returns the terrain before bunny in the list, the queue_free() is called before Global.GameState.hurt() can be called. This is only an issue if the free is immediate. It’s an edge case and doesn’t affect game play, but it other instances, could be important.

However, if the free is not immediate, we are queuing the free once for each object returned, which is just extra overhead for the garbage collector to look for an already freed object.

I just needed to look at the help. queue_free() queues up an object to be freed at the end of the current frame.

Also, in my suggestion above, there’s a need to ensure that the get_overlapping_bodies() returns a non-empty list before marking the object for freeing, so this entire suggestion is probably a wash.

Great course so far. I’m really enjoying it. Looking forward to the 3D stuff.

Privacy & Terms