Results 1 to 2 of 2

Thread: Freeing loaded texture

  1. #1

    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:
    Code :
    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?
    Code :
    spiritTexture  = null;
    Thanks in advance for your help.

  2. #2

    Re: Freeing loaded texture

    http://stackoverflow.com/questions/4776 ... e-on-webgl answers my question.
    Code :
    ctx.deleteTexture(spiritTexture);

Similar Threads

  1. Is there maximum amount of loaded kernels?
    By Kallex in forum OpenCL
    Replies: 2
    Last Post: 07-28-2011, 12:15 AM
  2. Freeing resources
    By shoosh in forum WebGL - General
    Replies: 6
    Last Post: 03-04-2011, 01:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •