Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
using System;
using Avalonia.Media;
using Avalonia.Media.Immutable;
using Avalonia.Rendering.Composition.Server;
using Avalonia.Rendering.Composition.Transport;

namespace Avalonia.Rendering.Composition.Server;

internal partial class ServerCompositionSimplePen : IPen
{
IDashStyle? IPen.DashStyle => DashStyle;
}

/// <inheritdoc/>
public override void Dispose()
{
// Dispose of the brush resource, this will remove the pen from the brush observers.
// This was causing the pen to be retained in memory by long lived brush resources (e.g. those defined in
// the theme or app resources), hence was causing memory leaks; see Issue #16451
SetValue(ref _brush, null!);
Copy link
Member

Choose a reason for hiding this comment

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

The property change will cause the pen to be queued for invalidation, which isn't needed since the object is being disposed. I think a better fix would be to call RemoveObserversFromProperty(ref _brush).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that makes sense, I'll make the change.
SetValue nulls the brush, so I'll set the brush to null, although it should not be necessary if the pen get GCed.

base.Dispose();
}
}
Loading