GC and textures

So I’ve been creating a lot of textures at runtime. I play with them for a few minutes. Create a couple of sprites with them. Call SetPixels a few times. The usual stuff. Then eventually the sprites get destroyed and the texture falls out of scope.

I’m assuming the GC comes along and picks the texture up just fine. There is no need for me to explicitly destroy it? Its not going to sit around unreferenced in graphics memory? How would I even tell? Does it even matter?

Also feel free to slap me around the ears, point me at the docs and tell me I’m being stupid worrying about nothing.

You can use the memory portion of the profiler to see what’s hanging about. I noticed that some textures I had created via Resources.Load were hanging about until I explicitly called Resources.UnloadUnusedAssets.

1 Like

Like most asset type unity objects, like materials and meshes, textures hang around until you forcibly remove or unload them. Resources.UnloadUnusedAssets will work. Object.Destroy aswell. Loading a new level also seem to get rid of them. But like andymads wrote the profilers memory section gives you some insight.

1 Like