Summary
Core components (Ledger, CRDT, Blockstore, Loader) have circular parent references that prevent garbage collection. This causes memory leaks when databases are opened and closed repeatedly.
Problem
The current architecture has:
CRDT holds reference to Ledger
Blockstore holds reference to CRDT
Loader holds references to multiple components
- These circular references prevent cleanup when
close() is called
Repeatedly opening and closing databases causes unbounded memory growth.
Proposed Solution
- Define clean interfaces in
core/types/:
ILedger, ICRDT, IBlockstore, ILoader
- Extract responsibilities from monolithic
Loader:
BlockLoader - block loading/caching
MetaLoader - metadata management
CompactionManager - compaction logic
- Replace parent object references with IDs
- Create
ComponentRegistry for service lookup
- Add event-based communication between components
Expected Outcomes
- Closing database releases all associated resources
- No references remain to closed database objects
- Components testable in isolation
- Memory stabilizes after 1000 open/close cycles
Summary
Core components (Ledger, CRDT, Blockstore, Loader) have circular parent references that prevent garbage collection. This causes memory leaks when databases are opened and closed repeatedly.
Problem
The current architecture has:
CRDTholds reference toLedgerBlockstoreholds reference toCRDTLoaderholds references to multiple componentsclose()is calledRepeatedly opening and closing databases causes unbounded memory growth.
Proposed Solution
core/types/:ILedger,ICRDT,IBlockstore,ILoaderLoader:BlockLoader- block loading/cachingMetaLoader- metadata managementCompactionManager- compaction logicComponentRegistryfor service lookupExpected Outcomes