Memory Leak with JS, XMLHttp request

Neil_H's icon

Hi everyone,

I’m hoping for some insight into a seeming memory leak issue on a maxmsp patch, which is a data sonification project in an installation which uses javascript XMLHttp requests to collect new data from an API every few minutes. The project is planned to be running long-term 24 hours a day, and currently the patch slowly starts using more and more RAM, such that over the course of 2-3 days it occupies about 50% of the available RAM and interferes with the function of other processes on the project computer (Windows Server 2016, 12 GB of RAM, running Max 8.1.5).

It appears that Max, with each XMLHttpRequest, is opening new sockets without closing them, and whatever garbage collection mechanism in Max is failing to clean up. The number of Max entries shown in netstat -anb at patch initialization is about 30, and after a day or two is much higher at over 14,000.

The javascript and a simplified version of the max patch are attached as screenshots. I’ve verified that this version has the same leak issue as the full patch.

Any advice you may have for how to handle this issue would be greatly appreciated. My collaborators and I are not hugely experienced with MaxMSP or JavaScript, and our online research yields answers that rely on browsers doing garbage collection for references that are external to javascript, and this doesn’t apply within the maxmsp context (e.g. https://javascript.info/garbage-collection).

Thanks in advance--!

Neil_H's icon

Hi again--any ideas anyone?
It is true we can restart max every 24 hours or so to clear the memory, but it is a bit of a hack and we'd like the sonification to be as continuous as possible--plus it would just be nice to better understand what is causing the memory leak.