Section 6: Instrument programming
Model 2651A High Power System SourceMeter® Instrument Reference Manual
6-32
2651A-901-01 Rev. A / March 2011
Lua does automatic memory management, which means you do not have to allocate memory for new
objects and free it when the objects are no longer needed. Lua manages memory automatically by
occasionally running a garbage collector to collect all objects that are no longer accessible from Lua.
All objects in Lua are subject to automatic management, including tables, variables, functions,
threads, and strings.
Lua uses two numbers to control its garbage-collection cycles. One number counts how many bytes
of dynamic memory Lua is using; the other is a threshold. When the number of bytes crosses the
threshold, Lua runs the garbage collector, which reclaims the memory of all inaccessible objects. The
byte counter is adjusted and the threshold is reset to twice the new value of the byte counter.