Had a memory leak on a project I am working on and after many test, found out that it was connected to setMask. Found a workaround but wondering if there's already another solution making this not an issue with setMask but rather with me understanding how to use setMask .
Here's a test code to replicate. First the code without setMask that seems to stay at the same memory over time:
new Frame(FIT, 1024, 768, dark, light, ready);
function ready() {
const rect = new Rectangle(400,400,blue,red,10).center();
const circleMask = new Circle(10).alp(0.5).center();
// test 1
circleMask.animate({
props: {radius:230}
});
};
Here's with setMask which seems to increase memory over time:
// test 2
rect.setMask(circleMask, true);
circleMask.animate({
props: {radius:230}
});
and lastly, here's with setMask and workaround that seems to stay at the same memory over time:
// test 3
rect.setMask(circleMask, true);
circleMask.animate({
props: {radius:230},
call: function() {
rect.setMask(null);
rect.setMask(circleMask);
}
});
My guess is that if a mask is animated, it will leak memory unless cleared using 'null'. I tried stopping the animation, just reassigning setMask after animation, but unless I first set to 'null' it would still leak. Hope this helps and if there's a better solution, please share.