<< free SYMSCI Toolbox heap >>

SYMSCI Toolbox >> SYMSCI Toolbox > gc

gc

garbage collection of symbolic objects

Calling Sequence

n = gc()
previous = gc( auto )

Arguments

n

integer

auto

boolean

previous

boolean

Description

This function controls and triggers the primitive garbage collection mechanism, which is used for all symbolic objects.

Every symbolic object is either a value or a variable object. Value objects carry intermediate results and may be deleted immediately after their usage. Variable object are those created by Variable(..). They should be assigned to Scilab variables and deleted manually using free(..).

Without input argument, gc() performs manual garbage collection, i.e. all value objects are deleted, and the number n of deleted objects is returned.

The argument auto sets the garbage collection mode to automatic (%t) or manual (%f) and returns the previous mode setting.

In automatic mode all value objects are deleted automatically after their first usage.

By default, the garbage collection mode is manual, this is most convenient for carrying out interactive calculations in the Scilab command window.

Examples

// tabula rasa
reset();

// switch to manual gc
gc(%f);

// create some symbols
// (hint: brackets indicates a variable object
//        and the number is the current heap count)
x = %(Sym("x"))
y = %(Sym("y"))

// calculate something
// (hint: parentheses indicates a value object
x*y + x

// calculate more ...
ans*ans + ans

// number of allocated objects?
heap()

// perform gc manually
gc()

// what is left?
heap()

// ok, let's clean up finally ...
free(x); free(y);
clear x y

// ... and we are back at?
heap()

See Also

Authors

Bibliography

SymEngine: C++ library for fast symbolic manipulation.


Report an issue
<< free SYMSCI Toolbox heap >>