Skip to content

Memory leak due to GridPartsResizeBehavior never disposes #7

Description

@izaksuilov

If i set GridPartsResizeBehavior.SetTarget(_grid, this); and I want to delete this behavior I should write smt like this GridPartsResizeBehavior.SetTarget(_grid, null!);

Even though I'm trying to set Target to null in this case, the previous behavior should still be disposed due to the code:
https://github.com/npolyak/NP.Ava.Visuals/blob/main/src/Behaviors/GridPartsResizeBehavior.cs#L147-L151

//...
behavior?.Dispose();
if (targetControl != null)
{
    behavior = grid.Children.AddBehavior(OnChildAdded, OnChildRemoved);
}
//...

BUT! If you decompile you can see that behavior isn't saved and it is always null so nothing is disposed (((IDisposable)null)?.Dispose();)

private static void OnTargetChanged(AvaloniaPropertyChangedEventArgs<Control> changedArgs)
{
	Grid grid = (Grid)changedArgs.Sender;
	Func<Point, double> shiftConverter = null;
	double initialSplitterPosition = 0.0;
	double initialShift = 0.0;
	double minChange = 0.0;
	double maxChange = 0.0;
	GridSplitter gridSplitter = null;
	Control targetControl = changedArgs.NewValue.Value;
	((IDisposable)null)?.Dispose();
	if (targetControl != null)
	{
		grid.Children.AddBehavior(OnChildAdded, OnChildRemoved);
	}
       //...

Please fix this cause it leads to memory leaks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions