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
MapleGcProtect - prevent garbage collection on an object in external code
MapleGcAllow - allow garbage collection on an object in external code
MapleGcIsProtected - test if an object is protected from garbage collection in external code
Calling Sequence
MapleGcProtect(kv, s)
MapleGcAllow(kv, s)
MapleGcIsProtected(kv, s)
Parameters
kv
-
kernel handle returned by StartMaple
s
Maple object
Description
These functions are part of the OpenMaple interface to Microsoft Visual Basic.
The MapleGcProtect function prevents the object, s, from being collected by the Maple garbage collector. The memory pointed to by s is not freed until Maple exits, is restarted, or a call to MapleGcAllow is issued. Any Maple objects that must persist between external function invocations must be protected. This includes any external global or static Maple objects that will be referred to at a later time. Failure to protect such a persistent variable can lead to unexpected results if the Maple garbage collector disposes of it between function calls.
The MapleGcAllow function allows the Maple garbage collector to reclaim storage used by the object, s. This does not necessarily mean that the storage will be reclaimed. It means that the object obeys the same rules applied to all other Maple objects, that is, objects can be collected when they are no longer actively referred to. Ensure that you only unprotect objects that were protected by your call to MapleGcProtect. Do no use MapleGcAllow on objects that you did not protect.
Another way to prevent an object from being garbage collected is to assign it as the value of any global name.
MapleGcIsProtected returns TRUE if the given object is protected from garbage collection.
Examples
Sub KeepResults(ByVal kv As Long)
Dim table, r, i As Long
table = MapleTableAlloc(kv)
'important to protect this table so it isn't collected
MapleGcProtect kv, table
For i = 1 To 10
r = EvalMapleStatement(kv, "rand();")
MapleTableAssign kv, table, ToMapleInteger(kv, i), r
Next i
MapleGcAllow kv, table
End Sub
See Also
gc, OpenMaple, OpenMaple/VB/API, OpenMaple/VB/Examples
Download Help Document