How do you 'queue_free' a material?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Macryc

I have a function that creates a new spatial material each time it’s called (it’s called very often), with another function that ‘removes’ the material by setting a mesh’s surface material to null.

By setting the surface material to null I’m simply ‘removing’ it from the mesh. BUT, since the material was first created via , I’m guessing it still sits in memory? How do you get rid of a material completely (similar to freeing a node)?

:bust_in_silhouette: Reply From: DDoop

SpatialMaterial derives from Resource, which derives from Reference. Resources are not free()'d in the same way Nodes are, instead Godot keeps a count of how many references a Material has (how many objects use it). From the docs:

“Unlike Objects, References keep an internal reference counter so that they are automatically released when no longer in use, and only then. References therefore do not need to be freed manually with”