Skip to content

refactor(memory): centralize tracked runtime heap allocation #31

Description

@TrixNEW

Problem

The VM already has helpers such as allocArray(), but some code still directly allocates runtime objects and manually adds them to tracking collections.

For example:

const arr = try self.allocator.create(PhpArray);
try self.arrays.append(self.allocator, arr);

This can bypass pooling, duplicate ownership logic, and make allocation-failure cleanup inconsistent.

The same should be audited for arrays, objects, strings, reference cells, generators, fibers, etc.

Changes

Route runtime heap allocations through centralized helpers such as:

  • allocArray()
  • allocObject()
  • allocOwnedString()
  • allocPersistentString()
  • allocRefCell()

Each helper should handle initialization, tracking, pooling, lifetime, and failure cleanup.

Acceptance criteria

  • Runtime heap objects use centralized allocation paths.
  • Pooling/tracking cannot be accidentally bypassed.
  • Tracking allocation failures clean up correctly.
  • No meaningful performance regression.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions