﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Paulo Quicoli commented on Reproducing a WPF memory leak</title><description>@jdu,
  
  
did you download my code? See, in my version, implementing INotifyPropertyChanged resolved memory leak...
</description><link>http://ayende.com/4296/reproducing-a-wpf-memory-leak#comment14</link><guid>http://ayende.com/4296/reproducing-a-wpf-memory-leak#comment14</guid><pubDate>Thu, 19 Nov 2009 18:19:15 GMT</pubDate></item><item><title>jdu commented on Reproducing a WPF memory leak</title><description>This looks _really_ bad to me. I think you should open a ticket about it at connect.microsoft.com. Because from my understanding of your case, it would mean almost any binding is leaking.
  
  
As someone wrote, there's a KB article describing a very similar leak here: 
[http://support.microsoft.com/kb/938416](http://support.microsoft.com/kb/938416). But in this KB there's an additional condition: the databinding source object X must hold a reference to the target of the binding. Which you don't have.
  
  
Your repro seems to imply that: 
  
Binding to a plain CLR object (no DependencyProperty and no INotifyPropertyChanged) without specifying Mode=OneTime always creates a memory leak.
  
  
And there are tons of those in every WPF app...
</description><link>http://ayende.com/4296/reproducing-a-wpf-memory-leak#comment13</link><guid>http://ayende.com/4296/reproducing-a-wpf-memory-leak#comment13</guid><pubDate>Thu, 19 Nov 2009 10:18:41 GMT</pubDate></item><item><title>Justin Chase commented on Reproducing a WPF memory leak</title><description>Mode=OneTime
  
  
or
  
  
Mode=OneWay
  
  
On those bindings.
</description><link>http://ayende.com/4296/reproducing-a-wpf-memory-leak#comment12</link><guid>http://ayende.com/4296/reproducing-a-wpf-memory-leak#comment12</guid><pubDate>Tue, 17 Nov 2009 20:19:52 GMT</pubDate></item><item><title>J commented on Reproducing a WPF memory leak</title><description>@Eyston
  
Between cross browser css hacks, javascript which behaves differently among different browsers and even browser versions, having to support every platform under the sun only to have to rebase your code every time a new version of a browser comes out...
  
boy I'm glad I develop desktop applications. :)
  
Also, BTW, WPF is the newest UI technology...Winforms (AFAIK) is much more stable since its approaching a decade in maturity
</description><link>http://ayende.com/4296/reproducing-a-wpf-memory-leak#comment11</link><guid>http://ayende.com/4296/reproducing-a-wpf-memory-leak#comment11</guid><pubDate>Tue, 17 Nov 2009 17:54:57 GMT</pubDate></item><item><title>Andrew commented on Reproducing a WPF memory leak</title><description>I haven't looked at Paulo's solution, so if his works, that's great.
  
  
In the last blog posting about this issue I believe I posted a "hackish" solution to the problem that should solve your problem.  It involves calling the GC and collapsing the process memory.  I'm in no way saying it's an ideal solution, but works in a pinch if everything else fails.
</description><link>http://ayende.com/4296/reproducing-a-wpf-memory-leak#comment10</link><guid>http://ayende.com/4296/reproducing-a-wpf-memory-leak#comment10</guid><pubDate>Tue, 17 Nov 2009 17:11:59 GMT</pubDate></item><item><title>Graham Nash commented on Reproducing a WPF memory leak</title><description>Does anyone have an easy way of doing such a clean memory dump in WinXP?  I tried using Debugging Tools for Windows, but WinDbg keeps complaining I am missing symbols.  (I followed the installation instructions on MSDN).
</description><link>http://ayende.com/4296/reproducing-a-wpf-memory-leak#comment9</link><guid>http://ayende.com/4296/reproducing-a-wpf-memory-leak#comment9</guid><pubDate>Tue, 17 Nov 2009 17:10:14 GMT</pubDate></item><item><title>Eyston commented on Reproducing a WPF memory leak</title><description>Reading posts / comments like this make me glad I'm not developing desktop applications.
  
  
There are just some things you can appreciate people knowing, that you have no desire to know yourself.  This kind of non-portable knowledge being one such case :)
</description><link>http://ayende.com/4296/reproducing-a-wpf-memory-leak#comment8</link><guid>http://ayende.com/4296/reproducing-a-wpf-memory-leak#comment8</guid><pubDate>Tue, 17 Nov 2009 14:55:44 GMT</pubDate></item><item><title>Paulo Quicoli commented on Reproducing a WPF memory leak</title><description>Ayende, as you can see in my code i changed you DataContext object to:
  
  
 public class MyModel: INotifyPropertyChanged
  
        {
  
            private string runningTime;
  
            public string RunningTime
  
            {
  
                get { return runningTime; }
  
                set
  
                {
  
                    runningTime = value;
  
                    OnPropertyChanged("RunningTime");
  
                }
  
            }
  
  
            private string memUsed;
  
            public string MemUsed
  
            {
  
                get { return memUsed; }
  
                set
  
                {
  
                    memUsed = value;
  
                    OnPropertyChanged(MemUsed);
  
                }
  
            }
  
  
            public void UpdateData()
  
            {
  
                RunningTime = DateTime.Now.ToString();
  
                MemUsed = GC.GetTotalMemory(true).ToString("#,#");
  
            }
  
  
            public event PropertyChangedEventHandler PropertyChanged;
  
  
            protected void OnPropertyChanged(string name)
  
            {
  
                PropertyChangedEventHandler handler = PropertyChanged;
  
                if (handler != null)
  
                {
  
                    handler(this, new PropertyChangedEventArgs(name));
  
                }
  
            }
  
        }
  
  
And in WPF Window, i chaged to:
  
  
&lt;stackpanel  
&lt;stackpanel  
&lt;textblock  
&lt;textblock  
&gt;  
&lt;stackpanel  
&lt;textblock  
&lt;textblock  
&gt;  
  
  
If you run, you will see memory is not getting high by time pass...  Memory leak is gone :)
  
(sorry for my bad english)
</description><link>http://ayende.com/4296/reproducing-a-wpf-memory-leak#comment7</link><guid>http://ayende.com/4296/reproducing-a-wpf-memory-leak#comment7</guid><pubDate>Tue, 17 Nov 2009 11:02:23 GMT</pubDate></item><item><title>Rafal commented on Reproducing a WPF memory leak</title><description>What the hell is MS.Utility.FrugalObjectList?
</description><link>http://ayende.com/4296/reproducing-a-wpf-memory-leak#comment6</link><guid>http://ayende.com/4296/reproducing-a-wpf-memory-leak#comment6</guid><pubDate>Tue, 17 Nov 2009 10:52:47 GMT</pubDate></item><item><title>Paulo Quicoli commented on Reproducing a WPF memory leak</title><description>Hi Ayende, i solved Memory Leak, take a look please:
  
  
[cid-b27ccfaa07b93be8.skydrive.live.com/.../....rar](http://cid-b27ccfaa07b93be8.skydrive.live.com/self.aspx/Public/memory%20leak%20solved.rar)</description><link>http://ayende.com/4296/reproducing-a-wpf-memory-leak#comment5</link><guid>http://ayende.com/4296/reproducing-a-wpf-memory-leak#comment5</guid><pubDate>Tue, 17 Nov 2009 10:06:56 GMT</pubDate></item><item><title>Michael Sync commented on Reproducing a WPF memory leak</title><description>Hi Szymon,
  
  
Please correct me if I
  
I tried changing like this below but it still keep increasing. 
  
  
1. 
  
  
&lt;itemscontrol  
&lt;itemscontrol.itemtemplate  
&lt;datatemplate  
&lt;border  
&lt;grid  
&lt;grid.columndefinitions  
&lt;columndefinition  
&lt;columndefinition  
&lt;columndefinition  
&gt;  
&lt;textblock  
                                               ToolTip="{Binding Path=Key,Mode=OneWay}"
  
                                               TextTrimming="CharacterEllipsis" /&gt;
  
&lt;gridsplitter  
                                                  Background="#3000"
  
                                                  Width="2"
  
                                                  Margin="2 0" /&gt;
  
&lt;textblock  
                                               Grid.Column="2" /&gt;
  
&gt;  
  
  
  
  
  
2. 
  
  
public class MainViewModel : ViewModelBase
  
    {
  
        public MainViewModel()
  
        {
  
            Statistics = new ObservableCollection
&lt;model(); 
  
        } 
  
  
        public void UpdateData() {
  
            Statistics.Clear();
  
            Statistics.Add(new Model("Time", DateTime.Now.ToString()));
  
            Statistics.Add(new Model("Mem", GC.GetTotalMemory(true).ToString("#,#"))); 
  
        }
  
  
        public ObservableCollection
&lt;model Statistics { get; set; }
  
    }
  
  
    public class Model : ViewModelBase
  
    {
  
        public Model(string str1, string str2)
  
        {
  
            key = str1;
  
            val = str2;
  
        }
  
  
        private string key = string.Empty;
  
        public string Key
  
        {
  
            get { return key; }
  
            set { 
  
                key = value;
  
                this.OnPropertyChanged("Key");
  
            }
  
        }
  
  
        private string val = string.Empty;
  
        public string Value
  
        {
  
            get { return val; }
  
            set
  
            {
  
                val = value;
  
                this.OnPropertyChanged("Value");
  
            }
  
        }
  
  
    }
  
  
Am I missing something? 
&gt;</description><link>http://ayende.com/4296/reproducing-a-wpf-memory-leak#comment4</link><guid>http://ayende.com/4296/reproducing-a-wpf-memory-leak#comment4</guid><pubDate>Tue, 17 Nov 2009 09:24:34 GMT</pubDate></item><item><title>grega_g commented on Reproducing a WPF memory leak</title><description>Here is kb article that i think describes your situation:
  
[http://support.microsoft.com/kb/938416/en-us](http://support.microsoft.com/kb/938416/en-us)  
  
</description><link>http://ayende.com/4296/reproducing-a-wpf-memory-leak#comment3</link><guid>http://ayende.com/4296/reproducing-a-wpf-memory-leak#comment3</guid><pubDate>Tue, 17 Nov 2009 09:20:13 GMT</pubDate></item><item><title>Szymon commented on Reproducing a WPF memory leak</title><description>Hi Ayende, 
  
The problem here is that you use a TwoWay binding to an object that doesn't provide change notification. This forces WPF to use other methods to synchronize the values. 
  
  
There are two solutions:
  
1) In your bindings use Mode=OneWay. Since you are recreating the items in each iteration you need to read the value only once.
  
2) Instead of DictionaryEntry use a custom class that implements INotifyPropertyChange interface. This way WPF is able to track changes to property values easily. 
  
  
</description><link>http://ayende.com/4296/reproducing-a-wpf-memory-leak#comment2</link><guid>http://ayende.com/4296/reproducing-a-wpf-memory-leak#comment2</guid><pubDate>Tue, 17 Nov 2009 09:16:41 GMT</pubDate></item><item><title>Michael Sync commented on Reproducing a WPF memory leak</title><description>I think Clear (istics.Clear();) may take a while to clean 
  
  
maybe. we can re-initialize Statistics 
  
  
 public void UpdateData() {
  
            Statistics = new ObservableCollection
&lt;dictionaryentry();
  
            Statistics.Add(new DictionaryEntry("Time", DateTime.Now.ToString())); 
  
            Statistics.Add(new DictionaryEntry("Mem", GC.GetTotalMemory(true).ToString("#,#"))); 
  
        }
&gt;</description><link>http://ayende.com/4296/reproducing-a-wpf-memory-leak#comment1</link><guid>http://ayende.com/4296/reproducing-a-wpf-memory-leak#comment1</guid><pubDate>Tue, 17 Nov 2009 09:12:36 GMT</pubDate></item></channel></rss>