Arena storage pool: Difference between revisions

Content deleted Content added
PureFox (talk | contribs)
Added Wren
Line 1,217: Line 1,217:
Finalizing ::oo::Obj4::Obj6 which held 10
Finalizing ::oo::Obj4::Obj6 which held 10
Finalizing ::oo::Obj4::Obj7 which held 11</span>
Finalizing ::oo::Obj4::Obj7 which held 11</span>

=={{header|Wren}}==
Memory is managed automatically by Wren's VM which allocates memory for new objects and reclaims that memory when those objects are no longer used.

However, the built-in List class (a dynamic array) does give the programmer some control of memory in that a minimum size can be specified when the List is created. It's also possible to request a garbage collection (though not for a specific unused object) by calling the System.gc method.

We can therefore simulate an arena storage pool as follows.
<lang ecmascript>var arena = List.filled(5, 0) // allocate memory for 5 integers
for (i in 0..4) arena[i] = i // insert some integers
System.print(arena) // print them
arena = null // make arena eligible for garbage collection
System.gc() // request immediate garbage collection</lang>

{{out}}
<pre>
[0, 1, 2, 3, 4]
</pre>


=={{header|zkl}}==
=={{header|zkl}}==