Freeing loaded texture

I am looking at the Textured Box demo on 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. … e-on-webgl answers my question.