WPF Memory Leak from Drag-Drop
wpf
Solution
I just discovered this gem myself, my solution was to use a WeakReference to the data item being dragged.
DataObject data = new DataObject(new WeakReference(this.draggedData));
DragDrop.DoDragDrop((DependencyObject)sender, data, DragDropEffects.Move);
and then in the drop
var draggedItem = e.Data.GetData(this.format.Name) as WeakReference;
if (draggedItem != null && draggedItem.IsAlive)
{
....
}
Problem
Using Red-Gate tools we have detected that the System.Windows.DataObject is holding a reference to a dragObject (a framework element) that is hanging around from an operation long since completed. How does one "clear" the drag object once DragDrop.DoDragDrop? Is there a way to pass a null through this and have it fall right through?