Forums > Javascript

How to explicitly free an MGraphics instance?

December 13, 2012 | 1:15 pm

Hi list,

With the example code below I am loading (large) Jitter matrices and rendering these with mgraphics within jsui. My issue is, I can’t find a way to free the MGraphics instance created by the mginstance function – every time i call it Max’s active memory allocation increases until it crashes.

How can I explicitly call a release on this MG instance (a kind of equivalent to the freepeer() method for jitter matrices)? I could not find a clue in the docs or DG’s tutorials.

Any tip or orientation would be much appreciated.

Best,
Frédéric

mgraphics.init();
mgraphics.relative_coords = 0;
mgraphics.autofill = 0;

var inputMatrix = new JitterMatrix();
var mg;
var outImage = null;
var width = (box.rect[2] – box.rect[0]); // clips to 2048
var height = (box.rect[3] – box.rect[1]); // clips to 2048

function load(val) // jxf.jit file as input
{
inputMatrix.read(val);
}

function mginstance()
{
mg = new MGraphics(width, height);

mg.image_surface_draw(inputMatrix.name);
outImage = new Image(mg);

bang();
}

function bang()
{
mgraphics.redraw();
}

function paint()
{
mgraphics.image_surface_draw(outImage);
}


December 14, 2012 | 2:01 pm

Ok, my problem was badly stated – I am now getting my matrix directly into an Image object without creating an MG instance for that purpose (appropriate code below for those interested). I had got confused (mainly) by the fact that the .fromnamedmatrix method on Image does not work for float32 matrices but only for 4 plane char, which I should have guessed earlier.

Best,
Frédéric

mgraphics.init();
mgraphics.relative_coords = 0;
mgraphics.autofill = 0;

var inputMatrix = new JitterMatrix();
var outImage = new Image();

function importmatrix(val)
{
inputMatrix.read(val); // must be 4 plane char
outImage.fromnamedmatrix(inputMatrix.name);
bang();
}

function bang()
{
mgraphics.redraw();
}

function paint()
{
mgraphics.image_surface_draw(outImage);
}


Viewing 2 posts - 1 through 2 (of 2 total)