Skip to content

[13.x] Free the previous chunk in lazy() and lazyById() - #62086

Merged
taylorotwell merged 1 commit into
laravel:13.xfrom
xurshudyan:lazy-free-previous-chunk
Oct 19, 2026
Merged

taylorotwell merged 1 commit into
laravel:13.xfrom
xurshudyan:lazy-free-previous-chunk

Conversation

@xurshudyan

Copy link
Copy Markdown
Contributor

When lazy() and lazyById() fetch the next chunk, the previous one has already been yielded and isn't needed anymore, but it's still held in $results. So two chunks are in memory at the same time and the peak memory is about twice as high as it needs to be.

This unsets the previous chunk before fetching the next one, the same as chunk() and chunkById() already do.

@taylorotwell
taylorotwell merged commit 0f4fb7a into laravel:13.x Oct 19, 2026
64 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants