10.6 Garbage Collector

Hollywood will invoke its garbage collector from time to time while your script is running. The garbage collector manages all resources allocated by your script and frees all memory that is no longer needed. For example:

Print("Hello World")

After Hollywood has called the Print() command the memory allocated for the string "Hello World" can be released because it is no longer needed. You can support the garbage collector by setting variables to Nil when you do not need them any longer. This is especially useful for long strings or extensive tables, e.g.

a = {}
For k = 1 To 1000
    a[k] = {e1 = x, e2 = y}
    x = x + 5
    y = y + 5

This code creates a pretty extensive table which occupies some memory of your system. If you do not need this table any longer, simply set it to Nil, e.g.

a = Nil

The garbage collector will then free the memory occupied by this table.

It is also strongly suggested that you use local variables whenever and wherever it is possible because the garbage collector can automatically release them when their scope ends (e.g. at the end of a function). See Local variables for details.

Show TOC