Skip to content

Commit

Permalink
perf: Dispose HashtableEx to return memory to the pool
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Jan 26, 2022
1 parent af1e5e7 commit 3db5555
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ internal void Set(object key, bool isAncestor)

internal void Clear()
=> _entries.Clear();

internal void Dispose()
=> _entries.Dispose();
}
}
}
1 change: 1 addition & 0 deletions src/Uno.UI/UI/Xaml/DependencyObjectStore.Binder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ private void BinderDispose()
}

_properties.Dispose();
_childrenBindableMap.Dispose();
}

private void OnDataContextChanged(object? providedDataContext, object? actualDataContext, DependencyPropertyValuePrecedences precedence)
Expand Down
4 changes: 4 additions & 0 deletions src/Uno.UI/UI/Xaml/DependencyObjectStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,10 @@ void Propagate(DependencyObjectStore store)
}
}
}

// Explicit dispose to return HashtableEx's internal array to the pool
// without having to rely on GC's finalizers.
ancestors.Dispose();
}

private static bool IsAncestor(DependencyObject? instance, AncestorsDictionary map, object ancestor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ internal void Add(_Key key, DependencyProperty[] value)
=> _entries.Add(key, value);

internal void Clear() => _entries.Clear();

internal void Dispose()
=> _entries.Dispose();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ internal void Remove(PropertyCacheEntry propertyCacheEntry)
internal int Count => _entries.Count;

internal void Clear() => _entries.Clear();

internal void Dispose()
=> _entries.Dispose();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ private bool TryGetTypeTable(Type type, out HashtableEx? table)
table = null;
return false;
}

internal void Dispose()
=> _entries.Dispose();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ internal void Add(Type key, bool isNullable)

internal void Clear()
=> _entries.Clear();

internal void Dispose()
=> _entries.Dispose();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ internal void Add(Type key, DependencyProperty[] dependencyProperty)

internal void Clear()
=> _entries.Clear();

internal void Dispose()
=> _entries.Dispose();
}
}
}
3 changes: 3 additions & 0 deletions src/Uno.UI/UI/Xaml/PropertyMetadataDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,8 @@ internal PropertyMetadata FindOrCreate(Type ownerType, CreationHandler createHan

return metadata;
}

internal void Dispose()
=> _table.Dispose();
}
}

0 comments on commit 3db5555

Please sign in to comment.