Posted 15 years ago
by Jon Cain
-
Software Architect,
AutoMon Corporation
Version: 10.1.0521
Platform: .NET 4.0
Environment: Windows 7 (64-bit)
Using RibbonEditorsStyleBehavior.ApplyRibbonCompatibleStyles="True" causes a child window to remain in memory forever, i.e., it's never garbage collected.
Here is some sample code that demonstrates the problem:
Window1.xaml -> "Main Window"Window1.xaml.cs
RibbonWindow1.xaml -> "Child Window"
RibbonWindow1.xaml.cs
Here is some sample code that demonstrates the problem:
Window1.xaml -> "Main Window"
<Window
x:Class="RibbonEditorMemoryLeak.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Button Click="OpenChildWindow_Click">Open Child Window</Button>
<Button Grid.Row="1" Click="GarbageCollect_Click">Garbage Collect</Button>
<TextBlock Grid.Row="2" FontWeight="Bold">Watch Debug Output for messages.</TextBlock>
</Grid>
</Window>
using System;
using System.Diagnostics;
using System.Windows;
namespace RibbonEditorMemoryLeak
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void OpenChildWindow_Click(object sender, RoutedEventArgs e)
{
Debug.WriteLine("OpenChildWindow_Click() -> Opening Child Window");
new RibbonWindow1().Show();
}
private void GarbageCollect_Click(object sender, RoutedEventArgs e)
{
Debug.WriteLine("GarbageCollect_Click()");
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
}
}
}
<ribbon:RibbonWindow
x:Class="RibbonEditorMemoryLeak.RibbonWindow1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:shared="http://schemas.actiprosoftware.com/winfx/xaml/shared"
xmlns:ribbon="http://schemas.actiprosoftware.com/winfx/xaml/ribbon"
xmlns:ribboneditors="http://schemas.actiprosoftware.com/winfx/xaml/ribboneditors"
ApplicationName="RibbonWindow1" Width="620" Height="420"
ribboneditors:RibbonEditorsStyleBehavior.ApplyRibbonCompatibleStyles="True">
<Grid>
<TextBlock TextWrapping="WrapWithOverflow">
This window will not get Garbage Collected because RibbonEditorsStyleBehavior.ApplyRibbonCompatibleStyles="True"
</TextBlock>
</Grid>
</ribbon:RibbonWindow>
using System.Diagnostics;
namespace RibbonEditorMemoryLeak
{
public partial class RibbonWindow1 : ActiproSoftware.Windows.Controls.Ribbon.RibbonWindow
{
public RibbonWindow1()
{
InitializeComponent();
Debug.WriteLine("RibbonWindow1() -> constructed");
}
~RibbonWindow1()
{
Debug.WriteLine("~RibbonWindow1() -> deconstructed");
}
}
}