Skip to content

Conversation

@guiyong
Copy link
Contributor

@guiyong guiyong commented May 7, 2024

Pull Request Template

Description

Set createValueFunc to null once the Func delegate is not needed. Without breaking the reference, the lambda function will keep capturing of any outer variables, in #4345, DocumentServiceRequest was captured, which prevent GC from recycling the request object, cause memory leak.

Below code, the request object will be captured by singleValueInitFunc delegate.

addresses = await this.serverPartitionAddressCache.GetAsync( 
                         key: partitionKeyRangeIdentity, 
                         singleValueInitFunc: (_) => this.GetAddressesForRangeIdAsync( 
                             request, 
                             cachedAddresses: null, 
                             partitionKeyRangeIdentity.CollectionRid, 
                             partitionKeyRangeIdentity.PartitionKeyRangeId, 
                             forceRefresh: false), 
                         forceRefresh: (_) => false); 

Type of change

Please delete options that are not relevant.

  • [] Bug fix (non-breaking change which fixes an issue)

Closing issues

To automatically close an issue: closes #4345

@kirankumarkolli
Copy link
Member

Closing due to inactivity, feel free to re-open as needed.

@guiyong
Copy link
Contributor Author

guiyong commented Feb 27, 2025

@kirankumarkolli, could you please let me know where I can re-open it. Thanks!

@kirankumarkolli kirankumarkolli marked this pull request as ready for review March 5, 2025 17:52
@kirankumarkolli
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@FabianMeiswinkel FabianMeiswinkel left a comment

Choose a reason for hiding this comment

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

LGTM

Pilchie
Pilchie previously approved these changes Mar 5, 2025
@guiyong guiyong dismissed stale reviews from Pilchie and FabianMeiswinkel via 2ff135b March 5, 2025 22:46
@kirankumarkolli
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@kirankumarkolli kirankumarkolli changed the title Set createValueFunc to null after the value being evaluated NonBlockingAsyncCache: Fixes lambda func capturing the outer context (memory optimization) Mar 8, 2025
@guiyong
Copy link
Contributor Author

guiyong commented Mar 8, 2025

@microsoft-github-policy-service agree company="Microsoft"

@guiyong
Copy link
Contributor Author

guiyong commented Mar 10, 2025 via email

@kirankumarkolli kirankumarkolli merged commit 93358ac into Azure:master Mar 11, 2025
23 of 26 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.

Memory usage for AddressCache - DocumentServiceRequest capture

4 participants