Maple Professional
Maple Academic
Maple Student Edition
Maple Personal Edition
Maple Player
Maple Player for iPad
MapleSim Professional
MapleSim Academic
Maple T.A. - Testing & Assessment
Maple T.A. MAA Placement Test Suite
Möbius - Online Courseware
Machine Design / Industrial Automation
Aerospace
Vehicle Engineering
Robotics
Power Industries
System Simulation and Analysis
Model development for HIL
Plant Modeling for Control Design
Robotics/Motion Control/Mechatronics
Other Application Areas
Mathematics Education
Engineering Education
High Schools & Two-Year Colleges
Testing & Assessment
Students
Financial Modeling
Operations Research
High Performance Computing
Physics
Live Webinars
Recorded Webinars
Upcoming Events
MaplePrimes
Maplesoft Blog
Maplesoft Membership
Maple Ambassador Program
MapleCloud
Technical Whitepapers
E-Mail Newsletters
Maple Books
Math Matters
Application Center
MapleSim Model Gallery
User Case Studies
Exploring Engineering Fundamentals
Teaching Concepts with Maple
Maplesoft Welcome Center
Teacher Resource Center
Student Help Center
Notes on Memory Management with Java OpenMaple
Description
In Java OpenMaple, a Maple expression is represented by an Algebraic object. As long as this object is alive a reference to the corresponding Maple expression is kept. This reference keeps the Maple expression from being collected by the Maple garbage collector. Once the Algebraic object is freed in Java, the Maple expression may also be freed by Maple.
In general, this system works well and allows the user to ignore the details of memory management. Unfortunately, there are some situations where this system leads to poor memory usage. In these situations the user must take more responsibility for some memory issues.
This system fails when Java is creating many Algebraic objects without invoking the Java garbage collector. An example of this is a tight loop that creates an Algebraic for each iteration of the loop:
for ( i = 0; i < 100000; i++ )
{
kernel.evaluate( "Array( 1..100000, fill="+i+");" );
}
In this situation Maple is using a large amount of memory, but Java is not. Since Java is not using much memory, it does not invoke its garbage collector frequently. This means that the Algebraic objects returned by evaluate are not freed often. Therefore, the Maple rtables referred to by the Algebraic objects are not collected. Since these objects use a large amount of memory, Maple is forced to allocate a large amount of memory from the system.
Calling dispose breaks the link between the Algebraic and the corresponding Maple expression. By doing so Maple is free to collect the expression. The above code should be rewritten as follows:
a = kernel.evaluate( "Array( 1..100000, fill="+i+");" );
a.dispose();
In this case Maple is free to collect the memory used by an rtable any time after dispose has been called. Once the dispose member function has been called on an Algebraic no other member functions may be called except isDisposed.
See Also
gc, OpenMaple, OpenMaple/Java/Algebraic OpenMaple/Java/Algebraic/dispose, OpenMaple/Java/Algebraic/isDisposed OpenMaple/Java/Examples, OpenMaple/Java/API
Download Help Document