Memory handling in lists/arrays allocation/deallocation



On 12/26/06, Elianto84 <elianto84 at gmail.com> wrote:
> I'd like to know how to efficiently manage lists/arrays
> allocation/deallocation in Maxima,
> 'cause i've experienced that the execution of a code like
>
> for i:... do (                /* lots of times */
> list :  certain_function_of_i_that_returns_a_list,
>  ...                           /* other operations over list */
> )
> maybe really RAM-consuming.

Maxima uses Lisp's garbage collector, so there is no need to allocate
or deallocate memory explicitly.  If an object is "reachable", then it
will not be deallocated.  Reachable means that it is programmatically
accessible either through a variable or through a data structure
(which directly or indirectly is the value of a variable).

In your example above, since you are re-assigning the variable "list"
to a new value each time through the loop, earlier values of list are
not reachable and will be reclaimed -- unless of course they are
accessible in some other way.  If you want to explicitly signal to the
Maxima/Lisp system that a variable's value is no longer needed, you
can assign a trivial value to it -- false or 0 or the empty list.

The details of the "other operations" may be relevant.  Also beware of
"intermediate expression explosion" -- sometimes symbolic calculations
get much larger than you might think.

             -s