Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: WPF ListView memory leak

Ahmed_Faraz:

I am working on WPF project where I need to continuously update a ListView. The problem is that there is a small memory leak whenever I update the List. I have made the following sample code where I simply update the ListView whenever the timer expires.


public partial class MainWindow : Window
{
private ObservableCollection dummyData = new ObservableCollection();
private System.Windows.Threading.DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer();
public MainWindow()
{
InitializeComponent();
dummyData.Add("abc");
dummyData.Add("abcd");
dummyData.Add("xyz");
dummyData.Add("abc1");
dummyData.Add("abc2");
dummyData.Add("abc3");
dummyData.Add("abc4");
dummyData.Add("abc5");
dummyData.Add("abc6");
dummyData.Add("abc7");
dummyData.Add("abc8");
timer.Interval = new TimeSpan(0, 0, 1);
timer.Tick += timer_Tick;
timer.Start();
}
public ObservableCollection DummyDataCollection
{
get
{
if (dummyData == null)
{
dummyData = new ObservableCollection();
}
return dummyData;
}
set
{
dummyData = value;
}
}
void timer_Tick(object sender, EventArgs e)
{
lvDataBinding.ItemsSource = null;
lvDataBinding.ItemsSource = dummyData;
}
}

Now when I run this application, the memory used by it keeps on increasing.Even though it increases in very small amount but I cannot ignore it in my project.

So my question is whether or not this the correct way to update the List. If yes then how can I avoid the memory leak



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: WPF ListView memory leak

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×