texture:releaseSelf()

Type Function
Object TextureResource
Library graphics.*
Revision 2017.3060
See also graphics.releaseTextures()
TextureResource

Overview

The graphics.newTexture() API pre-loads a texture/image and prevents it from being disposed even when there is no display object using it. In order to release the TextureResource object and restore automatic management for the texture, you must release it by calling texture:releaseSelf().

Alternatively, in a wider scope, graphics.releaseTextures() can be used to release all texture objects sharing the same type parameter.

Gotchas

After texture:releaseSelf() is called, only the texture handle is released and becomes invalid. All display objects which are using the TextureResource will hold on to their handles. The TextureResource itself will only be disposed after there are no display objects using it.

Example

local texture = graphics.newTexture( { type="image", filename="background.png" } )

-- If you no longer need the texture, release it to prevent memory leaks
texture:releaseSelf()