Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Repeater memoization memory leak #1886

Merged
merged 1 commit into from
Dec 1, 2024
Merged

Fix Repeater memoization memory leak #1886

merged 1 commit into from
Dec 1, 2024

Conversation

exyi
Copy link
Member

@exyi exyi commented Nov 19, 2024

If the ConditionalWeakTable references itself, it will get leaked by .NET Core GC: dotnet/runtime#12255

Fortunately, we don't really need the ConditinalWeakTable here:

  • Repeater should generally be a short-lived object, so strong references will also be collected reasonably soon
  • Between Load and PreRender, the viewmodels were pinned in the DataContext of all children and the children are in Children collection. Only after PreRender could those references be useful, but we can as well Clear the dictionary at that point.

@exyi exyi added the bug label Nov 19, 2024
@exyi exyi force-pushed the fix-Repeater-memory-leak branch from 73c55dd to 4bf8213 Compare November 19, 2024 21:21
[DataRow(DotvvmRequestType.Command, RenderMode.Server)]
public void Repeater_IsCollectible(DotvvmRequestType requestType, RenderMode renderMode)
{
var (repeaterRef, contextRef, viewModelRef) = NewMethod(requestType, renderMode);
Copy link
Member

Choose a reason for hiding this comment

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

I am a bit uncomfortable with the method name NewMethod :D

If the ConditionalWeakTable references itself, it will get leaked by
.NET Core GC: dotnet/runtime#12255

Fortunately, we don't really need the ConditinalWeakTable here:
* Repeater should generally be a short-lived object, so
   strong references will also be collected reasonably soon
* Between Load and PreRender, the viewmodels were pinned
   in the DataContext of all children and the children are in Children
   collection. Only after PreRender could those references be useful,
   but we can as well Clear the dictionary at that point.

Co-authored-by: Adam Štěpánek <[email protected]>
@exyi exyi force-pushed the fix-Repeater-memory-leak branch from 4bf8213 to eade18f Compare November 30, 2024 22:15
@exyi exyi merged commit 93691f9 into main Dec 1, 2024
14 checks passed
@exyi exyi deleted the fix-Repeater-memory-leak branch December 1, 2024 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants