# Is there a way to check for ( recently ) freed object ?

**URL:** <https://forum.godotengine.org/t/is-there-a-way-to-check-for-recently-freed-object/12772>\
**Category:** Archive\
**Created:** [February 28, 2021, 10:53am UTC](https://forum.godotengine.org/t/is-there-a-way-to-check-for-recently-freed-object/12772 "2021-02-28T10:53:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://forum.godotengine.org/uploads/default/original/2X/4/4b0a7fa8a6334634b94a13d421f0d99e6f04e21f.svg) [@system](https://forum.godotengine.org/u/system)\
**Post date:** [February 28, 2021, 10:53am UTC](https://forum.godotengine.org/t/is-there-a-way-to-check-for-recently-freed-object/12772/1 "2021-02-28T10:53:33Z")

</div>

| | | |
| --- | --- | --- |
| ℹ | **Attention** | Topic was automatically imported from the old Question2Answer platform. |
| 👤 | **Asked&nbsp;By** | Inces |

Doesn’t need additional description 🙂  
Everyone knows this error : unable… : previously freed instance on a null instance.  
Is there a way for checking if a node in array ceased to exist, in a way not provoking this error ? Checking Inside\_scene\_tree and if = null won’t work.

---

<div class="post-metadata">

**Author:** ![system](https://forum.godotengine.org/uploads/default/original/2X/4/4b0a7fa8a6334634b94a13d421f0d99e6f04e21f.svg) [@system](https://forum.godotengine.org/u/system)\
**Post date:** [February 28, 2021, 12:17pm UTC](https://forum.godotengine.org/t/is-there-a-way-to-check-for-recently-freed-object/12772/2 "2021-02-28T12:17:36Z")

</div>

| | | |
| --- | --- | --- |
| 👤 | **Reply From:** | Jayman2000 |

Yes. You can use [is\_instance\_valid()](https://docs.godotengine.org/en/stable/classes/class_@gdscript.html?highlight=is_instance_valid#class-gdscript-method-is-instance-valid). For example, this

```auto
var test = TestClass.new()

print(is_instance_valid(test))
test.free()
print(is_instance_valid(test))

```

will print “True” then “False”.

Thanks a lot 🙂

Inces | 2021-02-28 14:43

---

<div class="post-metadata">

**Author:** ![system](https://forum.godotengine.org/uploads/default/original/2X/4/4b0a7fa8a6334634b94a13d421f0d99e6f04e21f.svg) [@system](https://forum.godotengine.org/u/system)\
**Post date:** [January 18, 2023, 8:16am UTC](https://forum.godotengine.org/t/is-there-a-way-to-check-for-recently-freed-object/12772/3 "2023-01-18T08:16:18Z")

</div>

| | | |
| --- | --- | --- |
| 👤 | **Reply From:** | CakeLover |

As of Godot 3.5

You can also check if `node.is_queued_for_deletion()`

A really good example I encountered was when you have 2 Nodes `A` and `B` and both emit signals to each other and delete each other

Let’s say I have 2 `Area2D` nodes with the same script as such:

```auto
 extends Area2D

 func _area_entered(obj:Area2D): # area_entered signal connected

```

```
		# do something here

```

```auto
		obj.queue_free()

```

And they overlap as such:

![enter image description here](https://forum.godotengine.org/uploads/default/original/2X/3/387a56f8823e19fe76d7ca50685b67a671222984.png)

You would expect that `B` would have more priority and hence would delete `A`  
not giving a chance for `A`’s `_area_entered()` to be emitted and as such only `A` would be deleted? But nope that’s not how it works

In reality `queue_free()` waits for emitted signal functions to complete before deletion and as such both `A` & `B` get deleted (I learned this the hard way)

  

the solution? check for `is_queued_for_deletion()` !

```auto
 extends Area2D

 func _area_entered(obj:Area2D): # area_entered signal connected

```

```
	if(self.is_queued_for_deletion()):
	 	return

```

```auto
		# do something here

		obj.queue_free()

```

_But Cakelover_, you might ask, _where would we actually use this?_

Well this might particularly be helpful when merging the same instances like [I tried](https://stackoverflow.com/questions/75150315/merging-2-overlapping-area2d-nodes?noredirect=1#comment132625073_75150315)

Hope this helps 🙂
