Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[JsonStreamer] Fix memory leak by caching stream readers/writers#63000

Merged
nicolas-grekas merged 1 commit into
symfony:7.3from
mtarld:fix/json-streamer-memory-issue
Jan 9, 2026
Merged

[JsonStreamer] Fix memory leak by caching stream readers/writers#63000
nicolas-grekas merged 1 commit into
symfony:7.3from
mtarld:fix/json-streamer-memory-issue

Conversation

@mtarld
Copy link
Copy Markdown
Contributor

@mtarld mtarld commented Jan 8, 2026

Q A
Branch? 7.3
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #62952
License MIT

Each call to JsonStreamReader::read() and JsonStreamWriter::write() was executing require $path, which re-evaluated the generated PHP file and created new closures.

And these closures contain circular references (&$providers) that weren't being garbage collected, causing memory to grow unbounded.

The fix caches the closure returned by require $path so it's reused on subsequent calls with the same type.

  • Before: Memory grows from 12MB to 118MB+ after ~7000 iterations.
  • After: Memory stays stable at ~18MB regardless of iterations.

@nicolas-grekas
Copy link
Copy Markdown
Member

Thank you @mtarld.

@nicolas-grekas nicolas-grekas merged commit 58c7060 into symfony:7.3 Jan 9, 2026
12 checks passed
This was referenced Jan 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants