Home / Article / Unload Sprite Texture from Memory

Unload Sprite Texture from Memory

/
/
/
529 Views

This is a short article regarding my experiments on how to load and unload a sprite texture from memory.

Load Sprite
 

In this coroutine I’m loading a texture and creating a new sprite with the www.texture result. Then I’m using the following method to unload the sprite from memory, by calling Destroy on the texture  and setting the sprite reference to null.

Unload Sprite
 

But then I detected that the Texture was not being fully released from memory as you can see in the following screenshots.

After a few experiments, I found out that instead of creating the sprite directly from the www.texture, I should create a new Texture2D and use it to create the sprite.

Load Sprite Fix
 

This way the texture is fully released when calling the unload method as you can see on the following screenshots.

After checking the Profiler detailed view, I saw that the first method was loading 3 times the size of the texture and not releasing it completely.

Happy Coding

  • Facebook
  • Twitter
  • Google+
  • Linkedin
  • Pinterest
  • Reddit

Leave a Comment

Your email address will not be published. Required fields are marked *