Masive patcher with memory leak. Anybody hire out for revieweing patchers?
I have a patch that uses video and runs it through blobs and an external OCR to create text. It takes the text and does a very simple animation of it using JS. Everything works. It does exactly what it is supposed to do. But it leaks. I have gotten the leak down to about .1 MB per second, but it still crashes after a few hours.
I have taken it apart and run the components separately but just can't figure out where the leak is. I was wondering if anyone here hires out to review/edit code? Thanks for any help
Are you creating instances of jit.gl.text2d in the js? This has a leak in 5.1.4, which has been fixed for 5.1.5
-A
Yes but I used a work around for that. Unless it would still cause a leak to create an array of text2d objects and then just shuffle through the array setting their positions (below is an example of the code)? If so are their any issues with text3D?
autowatch = 1;
inlets = 1;
outlets = 0;
////Variables
textWord = "hello";
var i = -1;
/// build an array of 150 text2d objects
var textLineArray = new Array();
//var deadText=null;
for (j=0;j99){
i = 0;
}
////set text to nothing
textLineArray[i].text();
////set size, position, and color
var xMultiplier = Math.sin(Math.random()*360);
if (xMultiplier < 0){
xMultiplier = -0.6;
} else {
xMultiplier = 0.6;
}
var yMultiplier = Math.sin(Math.random()*360);
if (yMultiplier < 0){
yMultiplier = -1.3;
} else {
yMultiplier = 1.3;
}
var xPosition = Math.random()*xMultiplier;
var yPosition = Math.random()*yMultiplier;
var zPosition = -1.0;
var textSize = Math.floor(Math.random()*4)+4;
var textColor = textSize/16;
////set text2d object properties
textLineArray[i].color = [textColor,textColor,textColor,1.];
textLineArray[i].size(textSize);
textLineArray[i].position = [xPosition, yPosition, zPosition];
textLineArray[i].text(textWord);
textLineArray[i].draw();
}
Thanks for the info. Is 5.1.5 available yet? I need a stable version of this. Do you have any pointers as to creating multiple lines of scrolling text? They are in front of randomly located text. In all I am using around 200 text3d objects loaded into arrays. Any pointers would be welcomed.
pcmxa
5.1.5 won't likely be released for about a month. Regardless, I would recommend using one instance of jit.gl.text2d, as the cache for the text characters' bitmaps is still quite memory intensive for using many instances (regardless of any memory leak issues which would still be present with each save and recompile of your JS file in 5.1.4). For scrolling text, you might want to search the forum for "scrolling text". There are some examples provided, but you may need to change to work with a single instance of jit.gl.text2d.You can use a similar strategy to the one Andrew suggested in your other thread.
FWIW, jit.gl.text3d doesn't have the same memory intensive behavior that jit.gl.text2d has.
Josh,
Maybe I am not understanding the nature of the problem. I understand that the jit.gl.text2d object is memory intensive, that should just effect performance. The issue I am running into is that the jit.gl.text2d objects consume more and more memory as the program runs,even if it is never closed and reopened. Given that I have defined a preset array of text2ds, shouldn't the memory hold steady (none are being created or destroyed just having their attributes changed)? If my code above is inherently leaky could you point out where so I can understand the concept better? I have been reading up on javascript and thought I understood how gc worked.
I have reworked the patch so it only has three text2d objects using the suggestions you made in the other thread. It is running as a standalone now on a test machine. So far it is looking good, though it is very processor intensive to render scrolling text this way. he big plus is that when nothing is moving nothing is being rendered. Thanks for all your help with this, it is very much appreciated.
For those searching from scrolling text2d the code I ended up with is below (it is messy since I haven't had a chance to go back and clean it up. There is a matrix in the patch called "werds2" which feeds to a jit.window. I'll come back and post a simplified patch when I get a chance.
autowatch = 1 ;
inlets =1;
outlets = 1;
var page = [ ] ;
var index = 0 ;
var textColor = 0;
var poemLength = 19;
var moveAmount =0.005;
var alphaInc = 0.008;
var position = 0;
var alpha = 0;
var line = 0;
var myrender = new JitterObject ("jit.gl.render", "werds2") ;
myrender.erase_color = [0., 0., 0., 1.] ;
myrender.blend_enable = 1 ;
myrender.depth_enable = 0 ;
myrender.init = 0 ;
var blabla = new JitterObject ("jit.gl.text2d", "werds2") ;
blabla.blend_enable = 0;
blabla.depth_enable = 1 ;
blabla.automatic = 0 ;
blabla.font("Arial") ;
blabla.face("bold");
blabla.screenmode = 1;
blabla.align = 1;
blabla.antialias = 1;
blabla.tracking = 1.2;
blabla.color = [0.,0.,0.,0.,];
blabla.size(14) ;
function lineQuery(length){
if (length > 20){
length = 20;
}
poemLength = length;
post(poemLength);
index = 0;
}
function erase(){
for (e=0;e= .75-line*0.035){
line+=1;
alpha =0;
position = 0;
}
if (line>=poemLength){
loadIntervalIDArch.cancel();
line = 0;
index = 0;
//unloadIntervalIDArch.cancel();
//reset to black
}
if (!myrender.init){ // ########### ???
myrender.drawswap () ;
myrender.init = 1 ;
}
myrender.erase ( ) ;
for (i = 0 ; i < page.length ; i++) {
blabla.position = page[i].position ;
blabla.color = page[i].color ;
blabla.text (page[i].str) ;
blabla.size(page[i].size);
blabla.draw ( ) ;
}
myrender.drawswap ( ) ;
}
function unloadPoemData(){
position = page[line].position[1]+moveAmount;
alpha = (.75-line*.035)/position;
//post("Alpha is "+ alpha + " and line is " + line + " and page is an array of length "+ page.length+ "n");
post("line is "+ line + "n");
page[line].color = [alpha,alpha,alpha,alpha];
page[line].position[1] =position;
if (position >= 1.1){
line+=1;
alpha =0;
position = 0;
}
if (line>=poemLength){
unloadIntervalIDArch.cancel();
line = 0;
index = 0;
erase();
}
if (!myrender.init){ // ########### ???
myrender.drawswap () ;
myrender.init = 1 ;
}
myrender.erase ( ) ;
for (i = 0 ; i < page.length ; i++) {
blabla.position = page[i].position ;
blabla.color = page[i].color ;
blabla.text (page[i].str) ;
blabla.size(page[i].size);
blabla.draw ( ) ;
}
myrender.drawswap ( ) ;
}
Well, It looks like I spoke too soon. The scripts are still crashing max with a java error that points to thread 0 jit.gl.text2D object + do append as the crash point. he same scripts have been up and running on text3d objects for hours now with no problems.
I wrote a script to have all of the animation in the patcher handled by a single text2d object. It still crashed pointing at the text2d as the cause. So unless I have done something in my script to create the memory leak, it looks like I will be using text3d objects. Hope I can find a way to make the look better.
Anyway the script is attached below.