Browse Source

Hot-fixed memory leak caused by Canvas.Children.Clear() not releasing instances properly.

pull/15/head
mkonicek 15 years ago
parent
commit
34c4c27f34
  1. 13
      src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Drawing/GraphDrawer.cs
  2. 36
      src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Drawing/PositionedGraphNodeControl.xaml.cs
  3. 6
      src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Layout/PositionedNode.cs
  4. 2
      src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/ObjectGraphControl.xaml.cs

13
src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Drawing/GraphDrawer.cs

@ -26,6 +26,7 @@ namespace Debugger.AddIn.Visualizers.Graph
{ {
Canvas canvas; Canvas canvas;
TextBlock edgeTooltip = new TextBlock(); TextBlock edgeTooltip = new TextBlock();
static double animationDurationSeconds = 0.5;
public GraphDrawer(Canvas canvas) public GraphDrawer(Canvas canvas)
{ {
@ -50,8 +51,7 @@ namespace Debugger.AddIn.Visualizers.Graph
return; return;
} }
double seconds = 0.5; var durationMove = new Duration(TimeSpan.FromSeconds(animationDurationSeconds));
var durationMove = new Duration(TimeSpan.FromSeconds(seconds));
var durationFade = durationMove; var durationFade = durationMove;
DoubleAnimation fadeOutAnim = new DoubleAnimation(1.0, 0.0, durationFade); DoubleAnimation fadeOutAnim = new DoubleAnimation(1.0, 0.0, durationFade);
@ -82,7 +82,14 @@ namespace Debugger.AddIn.Visualizers.Graph
PointAnimation anim = new PointAnimation(); PointAnimation anim = new PointAnimation();
if (first) { if (first) {
anim.Completed += new EventHandler((o, e) => { Draw(newGraph); }); anim.Completed += (o, e) => {
Draw(newGraph);
if (oldGraph != null) {
foreach (var oldNode in oldGraph.Nodes) {
oldNode.ReleaseNodeVisualControl();
}
}
};
first = false; first = false;
} }
anim.From = node.LeftTop; anim.From = node.LeftTop;

36
src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Drawing/PositionedGraphNodeControl.xaml.cs

@ -59,6 +59,11 @@ namespace Debugger.AddIn.Visualizers.Graph.Drawing
/// <param name="node"></param> /// <param name="node"></param>
public void SetDataContext(PositionedNode node) public void SetDataContext(PositionedNode node)
{ {
if (node == null) {
this.DataContext = null;
this.listView.ItemsSource = null;
return;
}
this.DataContext = node; this.DataContext = node;
this.Root = node.Content; this.Root = node.Content;
this.items = GetInitialItems(this.Root); this.items = GetInitialItems(this.Root);
@ -97,25 +102,19 @@ namespace Debugger.AddIn.Visualizers.Graph.Drawing
void PropertyExpandButton_Click(object sender, RoutedEventArgs e) void PropertyExpandButton_Click(object sender, RoutedEventArgs e)
{ {
var clickedButton = (ToggleButton)e.Source; var clickedButton = (ToggleButton)e.Source;
ContentPropertyNode clickedNode = null; if (clickedButton.DataContext == null) return;
try ContentPropertyNode clickedNode = clickedButton.DataContext as ContentPropertyNode;
{ clickedNode = clickedButton.DataContext as ContentPropertyNode;
clickedNode = (ContentPropertyNode)(clickedButton).DataContext; if (clickedNode == null) {
} throw new InvalidOperationException("Clicked property expand button, button shouln't be there - DataContext is not ContentPropertyNode.");
catch(InvalidCastException)
{
throw new InvalidOperationException("Clicked property expand button, button shouln't be there - DataContext is not PropertyNodeViewModel.");
} }
PositionedNodeProperty property = clickedNode.Property; PositionedNodeProperty property = clickedNode.Property;
clickedButton.Content = property.IsPropertyExpanded ? "-" : "+"; clickedButton.Content = property.IsPropertyExpanded ? "-" : "+"; // could be done with a converter
if (property.IsPropertyExpanded) if (property.IsPropertyExpanded) {
{
OnPropertyExpanded(property); OnPropertyExpanded(property);
} } else {
else
{
OnPropertyCollapsed(property); OnPropertyCollapsed(property);
} }
} }
@ -123,7 +122,8 @@ namespace Debugger.AddIn.Visualizers.Graph.Drawing
void NestedExpandButton_Click(object sender, RoutedEventArgs e) void NestedExpandButton_Click(object sender, RoutedEventArgs e)
{ {
var clickedButton = (ToggleButton)e.Source; var clickedButton = (ToggleButton)e.Source;
var clickedNode = (ContentNode)(clickedButton).DataContext; var clickedNode = clickedButton.DataContext as ContentNode;
if (clickedNode == null) return;
int clickedIndex = this.items.IndexOf(clickedNode); int clickedIndex = this.items.IndexOf(clickedNode);
clickedButton.Content = clickedNode.IsExpanded ? "-" : "+"; // could be done by a converter clickedButton.Content = clickedNode.IsExpanded ? "-" : "+"; // could be done by a converter
@ -199,8 +199,10 @@ namespace Debugger.AddIn.Visualizers.Graph.Drawing
void SetEdgeStrokeThickness(ListViewItem listViewItem, int thickness) void SetEdgeStrokeThickness(ListViewItem listViewItem, int thickness)
{ {
var clickedNode = (ContentNode)listViewItem.DataContext; var propNode = listViewItem.DataContext as ContentPropertyNode;
var propNode = clickedNode as ContentPropertyNode; if (propNode == null) {
return;
}
if (propNode != null && propNode.Property != null && propNode.Property.Edge != null && propNode.Property.Edge.Spline != null) { if (propNode != null && propNode.Property != null && propNode.Property.Edge != null && propNode.Property.Edge.Spline != null) {
propNode.Property.Edge.Spline.StrokeThickness = thickness; propNode.Property.Edge.Spline.StrokeThickness = thickness;
} }

6
src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/Layout/PositionedNode.cs

@ -56,6 +56,12 @@ namespace Debugger.AddIn.Visualizers.Graph.Layout
/// </summary> /// </summary>
public PositionedGraphNodeControl NodeVisualControl { get; private set; } public PositionedGraphNodeControl NodeVisualControl { get; private set; }
public void ReleaseNodeVisualControl()
{
this.NodeVisualControl.SetDataContext(null);
this.NodeVisualControl = null;
}
void InitContentFromObjectNode(Expanded expanded) void InitContentFromObjectNode(Expanded expanded)
{ {
this.Content = new ContentNode(this, null); this.Content = new ContentNode(this, null);

2
src/AddIns/Debugger/Debugger.AddIn/Visualizers/Graph/ObjectGraphControl.xaml.cs

@ -62,8 +62,6 @@ namespace Debugger.AddIn.Visualizers.Graph
public void Refresh() public void Refresh()
{ {
Log.Info("Object graph - refresh");
GC.Collect();
// Almost all of the blocking is done ContentPropertyNode.Evaluate, // Almost all of the blocking is done ContentPropertyNode.Evaluate,
// which is being called by WPF for all the properties. // which is being called by WPF for all the properties.
// It would be better if we were filling the node texts ourselves in a loop, // It would be better if we were filling the node texts ourselves in a loop,

Loading…
Cancel
Save