-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Repeater memoization memory leak
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]>
- Loading branch information
Showing
2 changed files
with
27 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/Framework/Framework/Utils/ReferenceEqualityComparer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.Collections.Generic; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace DotVVM.Framework.Utils | ||
{ | ||
// TODO next version: Replace with System.Collections.Generic.ReferenceEqualityComparer | ||
internal class ReferenceEqualityComparer<T> : IEqualityComparer<T> | ||
where T : class | ||
{ | ||
public static ReferenceEqualityComparer<T> Instance { get; } = new ReferenceEqualityComparer<T>(); | ||
|
||
|
||
public bool Equals(T? x, T? y) => ReferenceEquals(x, y); | ||
public int GetHashCode(T obj) => obj == null ? 0 : RuntimeHelpers.GetHashCode(obj); | ||
} | ||
} |