Array find function could not find null corresponding to the freed object, is this the expected result?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By 011eh
extends Node2D

var a :=[, null]

func _ready():
	print('a[0] == null: ',a[0] == null)
	print('a[0] == a[1]: ',a[0] == a[1])
	print('a.find(null): ',a.find(null))
	a[0] = null
	print('a.find(null): ',a.find(null))


a[0] == null: true
a[0] == a[1]: true
a.find(null): 1 # expected return 0
a.find(null): 0
:bust_in_silhouette: Reply From: zhyrin

A freed node might be evaluatable as null, but that doesn’t mean it’s value is null.
In other words, a freed node doesn’t automatically become null.
You would need to explicitly set the value at index 0 to null as well, as you did.

Note: You should queue_free() nodes instead of free(), in case they are referenced elsewhere in the same frame.