Skip to content

Object lifetime

For a retained bullet reference:

1
2
3
if (GD.isInstanceValid(bullet)) {
    bullet.queueFree()
}
1
2
3
if (GD.isInstanceValid(bullet)) {
    bullet.queueFree();
}
1
2
3
if (GD.isInstanceValid(bullet)) {
  bullet.queueFree()
}

queueFree() schedules deletion of the node and its children at the end of the frame. Scene-owned nodes are freed with their parent; dropping a JVM reference does not free a node.

A reference can outlive its node

A non-null JVM reference may refer to a deleted Godot object. GD.isInstanceValid() returns false for null or freed objects. Do not call methods on a freed object.