0

I have a question about memory and pointers/references in javascript, in particular p5js.

I declare a list at the top of my code:

var my_list;

then I can access this inside any function as it is "global".

In my main code, I have an eternal loop in which I visualise my_list, then calculate a new list temp_list. At the end of the loop I want to swap these lists, so that my_list points to the newly created temp_list. Actually, I also want to free up the memory being used by the previous list as I don't need it any more.

repeated_forver(){

// visualise my_list

// calculate temp_list
var temp_list = .. something ...

// point my_list to new data
my_list = temp_list;

}

Will this do what I want it to do?

  • my_list points to the newly calculated data, temporarily help under the name temp_list
  • garbage collect the data that was previously pointed to by the name my_list

Is this how javascript works? My initial research suggested that structures like lists are referred to by name / pointer and this does work.

0 Answers0