Forums > Javascript

How to safely free memory for object created with JS ?

May 28 2012 | 2:54 pm

Hi there,

my JS code create Max Objects on the patcher (=not encapsulated in JS)
I keep a trace of all objects created in JS arrays in order to be able to have a reference to them and to pass data, track etc.

If I want to make a safe clean, to free completely the memory related to that, I’m removing my objects from the patcher, but what SHOULD I do with my arrays ?

Actually, I’m basically doing that:
myArray.length = 0;

When I’m using JAVA, I have to explicitely call freePeer() method for each instantiated object.
BUT should I do that in JS if my code already removed the objects in the patcher …?

( I guess no, but I’d prefer to be sure)

May 30 2012 | 10:05 am

I think js have a GC you don’t worried about that..

If I’m not wrong .. max object pointer was managed by max application it self …when created max object in javascript object you just got a reference to that object … may be you can use yourObjectArray[n].valid to check state of your ref.

Jun 04 2012 | 1:03 pm

Yes in a browser JS will auto GC depending on scope of the var, I assume max adhere’s to that. I guess it’s analogous to having a var reference an element to the DOM, if the var no longer exists, the element still will, unless you call an element.removeChild(). You can also do a delete on elements in an array but again it will only delete the pointer to the object.

Jun 04 2012 | 1:19 pm

hi there,
many thanks for your answers.
I got it

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

Forums > Javascript