Forums > Max For Live

Are LiveAPI objects instantiated in JS garbage collected ?

Jan 25 2012 | 3:03 pm

Hi there,

Creating an array of LiveAPI objects, I’d like to know if objects are really killed if I splice all elements of that array.
It doesn’t seem from a performance/efficiency point of view.

Indeed, my liveset is ok, no lag nothing.
I put the device, if I build a lot of callback, it lags a very bit (only the audio meters)
If I click on my button which splices ALL object in the array, it still lags.
If I delete the device, then undo, no more lags.

any infos?

Jan 25 2012 | 4:04 pm

I would imagine that a formal declaration of array to be null (as opposed to calling methods to remove objects from the patcher) might help.

Could you post your code?

Jan 25 2012 | 4:14 pm

Problem is:
I have an array with a length of n.

I decide to activate this or that parameters to be listened (= create the corresponding LiveAPI object w/its callback)
It puts it inside the array at the index 3 for instance.

Same with another one at index 5.

Then, I want to remove the object in 3 (= I don’t want max to listen a specific parameter anymore)


Jan 25 2012 | 4:31 pm

I still think my suggestion is worth a try.

Jan 25 2012 | 4:45 pm

tried. same.

problem isn’t the array but the objects which seem to remain in memory/cpu cycles or whatever.
sounds strange.
first time I experiment that

Jan 25 2012 | 5:00 pm

Could you post your code pls?



Jan 25 2012 | 7:04 pm

Live API objects aren’t going to get collected, I think. Id’s are persistent, even if no longer assigned (I asked someone about this before, but perhaps something has changed since then). I don’t know how this figures into memory management within js, though.

One thing you can do is remove the callback from the API by assigning the = 0. This generally gets rid of any overhead I have. Just removing the js object’s assignment does NOT remove the API object itself, afaik.

After rereading your post, I think that’s what you are after: reassign the .property of the object to 0.


btw, assignment of the array to null will lead to api errors (or at least it used to, the last time I tried it).

Jan 25 2012 | 7:43 pm

for sure, it only remove the reference and garbage collection can happen but of course doesn’t free the placeof the LiveAPI objects.
removing the callback doesn’t help a lot as far as I tested.

I asked to Andrew who probably answer here.

thanks for the explorations :)

if you are interested by the purpose, you can check this :

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

Forums > Max For Live