Skip to content

Memory leak in \Carbon\AbstractTranslator::resetMessages() #57

@uh-zuh

Description

@uh-zuh

Describe the bug
Memory leak in \Carbon\AbstractTranslator::resetMessages()

To Reproduce

for ($i = 0; $i < 20000; $i++) {
    \Carbon\Carbon::getTranslator()->resetMessages('en');
    if (mt_rand(0, 99) === 0) {
        echo "memory: " . (int)(memory_get_usage() / 1024 / 1024) .  "\n";
    }
}

Expected behavior
No memory leak

Actual behavior
Output:

memory: 8
memory: 8
memory: 12
...
memory: 123
memory: 124
memory: 126
PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 32768 bytes) in /app/laravel-app/vendor/nesbot/carbon/src/Carbon/Lang/en.php on line 1

Versions

  • PHP: 8.4.11
  • Carbon: 3.10.2

Additional context
I have faced with this memory leak in Pest tests in Laravel application.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions