Skip to content

Instantly share code, notes, and snippets.

@willnationsdev
Last active July 3, 2017 01:52
Show Gist options
  • Save willnationsdev/ca3b8954bde921983bfafebeb75c267d to your computer and use it in GitHub Desktop.
Save willnationsdev/ca3b8954bde921983bfafebeb75c267d to your computer and use it in GitHub Desktop.
Godot Deletion Guide
# Reference in GDScript:
# The refcount is incremented on assign, pass as argument, etc. It's decremented...:
# Members: when the instance is freed.
# Locals: it's a bit weird in this case though. You would expect it to be on scope
# exit like in C++, but it's actually on function return. However, and this
# is the weird part, if there are two locals at the same stack address, the
# refcount is decremented when the latter local is first assigned. e.g.:
func hello_there():
if whatever:
var myref = Reference.new()
print(myref)
# myref is still alive here, after exiting its scope. it's not visible though
return # the refcount for myref is decremented here, it's freed since it reaches 0
func oh_its_you():
if whatever:
var myref = Reference.new()
print(myref)
# myref is still alive here, after exiting its scope. it's not visible though
if whatever:
# myint is on the same stack address as myref,
# therefore it replaces the Variant at that address.
# the previous Variant at that stack address (the one for myref) dies,
# so the refcount for myref is decremented here instead
var myint = 10
print(myint)
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment