L
Lloyd Dupont
I have a very simple WPF Application (code inline below).
If, as a user, I click "Web Frame" then "Nothing" (then, optionally,
"GC.Collect")
A Frame object has been created and removed from all hierarchy yet it stays
in memory (as a memory profile will tell you).
Now, what can I do about that?
As my application run, I lose memory from multiple Frame object created
dynamically (which are not collected)!!!
Worst than that on some of them I navigate to multimedia content and the
music keeps playing without way of stopping it!
== Window1.xaml ===
<Window x:Class="FrameMemLeak.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Memory Leak in XAML"
Height="400" Width="400">
<DockPanel>
<StackPanel DockPanel.Dock="Left" Orientation="Vertical">
<Button Content="Web Frame" Click="OnWebFrame"/>
<Button Content="Nothing" Click="OnNothing"/>
<Button Content="GC.COllect()" Margin="0,10,0,10" Click="OnCollect"/>
</StackPanel>
<Border x:Name="carea" BorderThickness="1" BorderBrush="Black" />
</DockPanel>
</Window>
=== Windows1.xaml.cs ===
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void OnWebFrame(object sender, RoutedEventArgs e)
{
carea.Child = new Frame() { Source = new Uri("http://www.google.com") };
}
private void OnNothing(object sender, RoutedEventArgs e)
{
carea.Child = null;
}
private void OnCollect(object sender, RoutedEventArgs e)
{
GC.Collect();
}
}
================
If, as a user, I click "Web Frame" then "Nothing" (then, optionally,
"GC.Collect")
A Frame object has been created and removed from all hierarchy yet it stays
in memory (as a memory profile will tell you).
Now, what can I do about that?
As my application run, I lose memory from multiple Frame object created
dynamically (which are not collected)!!!
Worst than that on some of them I navigate to multimedia content and the
music keeps playing without way of stopping it!
== Window1.xaml ===
<Window x:Class="FrameMemLeak.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Memory Leak in XAML"
Height="400" Width="400">
<DockPanel>
<StackPanel DockPanel.Dock="Left" Orientation="Vertical">
<Button Content="Web Frame" Click="OnWebFrame"/>
<Button Content="Nothing" Click="OnNothing"/>
<Button Content="GC.COllect()" Margin="0,10,0,10" Click="OnCollect"/>
</StackPanel>
<Border x:Name="carea" BorderThickness="1" BorderBrush="Black" />
</DockPanel>
</Window>
=== Windows1.xaml.cs ===
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void OnWebFrame(object sender, RoutedEventArgs e)
{
carea.Child = new Frame() { Source = new Uri("http://www.google.com") };
}
private void OnNothing(object sender, RoutedEventArgs e)
{
carea.Child = null;
}
private void OnCollect(object sender, RoutedEventArgs e)
{
GC.Collect();
}
}
================