simap / pixelblaze

Files related to Pixelblaze
https://www.bhencke.com/pixelblaze
233 stars 29 forks source link

Memory/Garbage Collection/passing-by-value or -reference? #9

Closed pavellishin closed 5 years ago

pavellishin commented 5 years ago

I have a few questions about how garbage collection and memory management works in functions.

When I do something like

var banana = 1;

function multiplyBanana(banana) {
  var multiplicand = 12;
  return banana * multiplicand;
}
  1. Is another unreclaimable part of memory allocated for the banana inside the function?
  2. Is another unreclaimable part of memory allocated for the multiplicand inside the function?
simap commented 5 years ago

In your example banana and multiplicand are allocated on the stack and freed (popped) when the function exits. In Pixelblaze's language, arrays and functions are passed by reference, everything else is a primitive number and passed by value. The language is es6 in syntax, but a limited subset of functionality is supported, and all numbers are 16.16 fixed point. It is compiled to a mostly static memory model, with the exception that arrays are dynamically created, but there is no GC yet.