Memory Management
Memory safety is a primary goal of the Rava2 project. We employ several strategies to ensure a robust execution environment.
Safety Suite
All memory allocations in Rava2 are wrapped in a safety layer that provides:
- Overflow Protection: Integer overflow checks before any allocation.
- Null Verification: Automatic checks for allocation failure.
- Pointer Nullification: The
RAVA_FREEmacro ensures pointers are set to NULL after being freed.
Garbage Collection
Java objects are managed by a Mark-and-Sweep Garbage Collector. The GC is triggered automatically when the heap reaches a certain threshold or can be invoked manually via System.gc().
// Example of manual GC trigger
System.gc();
The Arena
For high-performance parsing, an Arena Allocator is used. This allows for fast, bulk allocation of AST nodes that are all freed at once when parsing is complete.