Freeing loaded texture

I am looking at the Textured Box demo on http://www.khronos.org/webgl/wiki/Demo_Repository. It has the following code snippets:


function loadImageTexture(ctx, url)
{
    var texture = ctx.createTexture(); // allocate texture
    texture.image = new Image();
    texture.image.onload = function() { doLoadImageTexture(ctx, texture.image, texture) }
    texture.image.src = url;
    return texture;
}

function doLoadImageTexture(ctx, image, texture)
{
    ctx.bindTexture(ctx.TEXTURE_2D, texture);
    ctx.texImage2D(ctx.TEXTURE_2D, 0, ctx.RGBA, ctx.RGBA, ctx.UNSIGNED_BYTE, image);  // loaded the image
...
}
...

var spiritTexture = loadImageTexture(gl, "resources/spirit.jpg");

How do you free allocated/loaded texture in order to avoid memory leak?

Will the following code free both the loaded/allocated texture and image?

spiritTexture  = null;

Thanks in advance for your help.

http://stackoverflow.com/questions/4776 … e-on-webgl answers my question.

ctx.deleteTexture(spiritTexture);