Allocating objects

An M-Business Client JavaScript program can allocate an unlimited number of values when only a fixed number of values are in use at any one time. For example, consider the following loop:

for (var x = 0 ; x < 100000 ; ++x) { 
  var obj = new Object; 
  obj.foo = 4; 
}

This loop will run without problems in M-Business JavaScript (although it may take some time to complete.). The loop allocates 100,000 objects, but each allocated object becomes garbage as soon as the next loop iteration begins, so only one object is actually in use at any given time. The following loop, on the other hand, may run out of memory:

var a = new Array; 
for (var x = 0 ; x < 1000 ; ++x) { 
  var obj = new Object; 
  obj.foo = 4; 
  a[a.length] = obj; 
}

This loop allocates 1000 objects and keeps them all in use by storing them in an array.