Skip to content

[Architecture] Break circular references between core components #1500

@bbopen

Description

@bbopen

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

  1. Define clean interfaces in core/types/:
    • ILedger, ICRDT, IBlockstore, ILoader
  2. Extract responsibilities from monolithic Loader:
    • BlockLoader - block loading/caching
    • MetaLoader - metadata management
    • CompactionManager - compaction logic
  3. Replace parent object references with IDs
  4. Create ComponentRegistry for service lookup
  5. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions