Algebraic.disposeallows the expression represented by an Algebraic to be collected by the Maple garbage collector
Calling SequenceDescriptionExamples
<Text-field style="Heading 2" layout="Heading 2" bookmark="usage">Calling Sequence</Text-field>
void dispose() throws MapleException
<Text-field style="Heading 2" layout="Heading 2" bookmark="info">Description</Text-field>
The dispose functions allows a Maple expression that is represented by an Algebraic object to be collected by the Maple garbage collector. Once dispose has been called on an Algebraic, it is an error to call any member function other than isDisposed.
Every Algebraic object represents a Maple expression. The Algebraic objects keep the corresponding Maple expression from getting collected by the Maple garbage collector. When the Java garbage collector collects the Algebraic object, the link between it and the Maple expression is broken, and Maple may collect the expression.
In some situations the Java garbage collector may be too slow in collecting the Algebraic objects. When this happens, Maple is unable to reuse the memory and so it must allocate more. Calling dispose on objects that are no longer needed may fix this problem.
<Text-field style="Heading 2" layout="Heading 2" bookmark="examples">Examples</Text-field>
import com.maplesoft.openmaple.*;import com.maplesoft.externalcall.MapleException;class Example{ public static void main( String notused[] ) throws MapleException { String[] mapleArgs = { "java" }; Engine engine = new Engine( mapleArgs, new EngineCallBacksDefault(), null, null ); Algebraic a1; int i; for ( i = 0; i < 100000; i++ ) { a1 = engine.evaluate( "Array( 1..10^4 ):" ); a1.dispose(); } Numeric n = (Numeric)engine.evaluate( "kernelopts( bytesalloc ):" ); System.out.println( "Total Bytes Alloc: "+n ); }}
Executing this code should produce output similar to the following, with the bytes used messages removed.
Total Bytes Alloc: 6945544
See AlsoExternalCalling/Java/MapleExceptionOpenMapleOpenMaple/Java/AlgebraicOpenMaple/Java/Algebraic/isDisposedOpenMaple/Java/APIOpenMaple/Java/Engine/evaluateOpenMaple/Java/memory