Skip to content

Reduce AsyncLazy value factory retention to improve GC-test stability#1552

Merged
AArnott merged 1 commit intomainfrom
dev/andarno/stabilizeTests
Feb 26, 2026
Merged

Reduce AsyncLazy value factory retention to improve GC-test stability#1552
AArnott merged 1 commit intomainfrom
dev/andarno/stabilizeTests

Conversation

@AArnott
Copy link
Member

@AArnott AArnott commented Feb 26, 2026

No description provided.

Copilot AI review requested due to automatic review settings February 26, 2026 16:29
@AArnott AArnott enabled auto-merge February 26, 2026 16:29
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces the retention time of the value factory delegate in AsyncLazy<T> to improve garbage collection behavior and test stability. The change introduces early nulling of captured variables to allow the GC to reclaim memory sooner.

Changes:

  • Adds localValueFactory variable to store the value factory reference before nulling the captured originalValueFactory
  • Nulls originalValueFactory immediately after copying it to reduce closure retention
  • Nulls localValueFactory in the finally block to ensure cleanup after the factory executes

Copy link
Member

@sandyarmstrong sandyarmstrong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised this makes such a difference in GC.

@AArnott AArnott merged commit 2f19f04 into main Feb 26, 2026
13 checks passed
@AArnott AArnott deleted the dev/andarno/stabilizeTests branch February 26, 2026 17:49
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.

3 participants