Known Issue: VSM/DatePicker Memory Leak

NOTE: This issue has been fixed in the January 2009 Release of the WPF Toolkit.

There is a memory leak in VisualStateManager caused by the attached VisualStateBehaviors which arises whenever a call is made to VisualStateBehaviors.AddValueChanged. This leak manifests itself in the DatePicker control and we do not recommend shipping the DatePicker in production code unless this issue is fixed. The WPF team is currently working on a fix for this issue and will release that fix as soon as possible.

In the meantime, if you need to ship the DatePicker prior to the release of the official fix, there are some steps you can take to implement a workaround to prevent calls to VisualStateBehaviors.AddValueChanged. All of the behaviors which ship with the Toolkit make this call in their OnAttach method, therefore, a workaround must either prevent the stock behaviors from loading, or prevent them from calling OnAttach. VisualStateBehaviorsFactory controls the automatic loading of stock behaviors as long as the VisualStateBehavior property has the default value. A workaround could prevent the automatic loading of stock behaviors by setting this property. However, a new behavior would have to be set, and that behavior would need to implement its own way of listening to property change events. In addition, behaviors for ButtonBase, ToggleButton, ListBox, and ProgressBar would need to be provided.

The workaround is fairly complicated and would require a good deal of work, so our recommendation is for developers to wait for the official fix if at all possible. Please note that this issue will not be present in the .NET 4.0 version of these components, since VisualStateBehaviors will not be included in the final version of VSM.

Last edited Jan 30, 2009 at 10:06 PM by SamanthaMSFT, version 2

Comments

yagnesh2879 Jul 21, 2009 at 7:15 AM 
Datepicker Tooltip binding Problem.
when use validation.ErrorTemplate and apply ValidationRule at that time error iis not display in datepicker tooltip. but as it working good with Textbox.

sureshch Feb 16, 2009 at 1:39 PM 
I download this WPF ToolKit. But I unable to run this application. When I open this project in Visual Studio 2008, I am getting One Error. So Please help how to run this application. I installed WPFToolKit.msi file. Still I am getting Errors.

I need this application. So, Please send me instructions for this application. my Id : chsureshmca@gmail.com

agsmith Feb 13, 2009 at 12:16 PM 
I haven't tried it out - was just reading the code - but it seems to me like while the original leak issue I reported was fixed there are still some issues/bad assumptions. For one I see that the OnAttach of the ControlBehavior hooks the Loaded but it never unhooks so it could well hook multiple times (e.g. if you switch to a tab that contains the control to another and back since that will cause the loaded/unloaded which causes the base class to call Attach/Detach as it is loaded/unloaded). Second, the base class seems to assume that the VisualStateBehavior will only change while the control is loaded because its directly calling the Attach. If the control were unloaded it would still call the Attach method which would reattach the handlers (and hook the Unloaded - possibly for the second time - and unhook the Loaded event which may not have been hooked).

SamanthaMSFT Jan 30, 2009 at 7:30 PM 
Thanks :-) Yes, this is fixed but the fix hasn't been posted to the site yet. We'll release a new update with the fix within the next few days.

nick_ch Jan 30, 2009 at 9:15 AM 
Is this fixed now?
Thanks for the great work

SamanthaMSFT Jan 29, 2009 at 5:32 PM 
We actually are currently in the process of signing this fix and posting it to the site. Please be on the lookout - it should be available in a few days :-)

mihailik Jan 28, 2009 at 6:44 AM 
>to wait for the official fix if at all possible

Perhaps not on this week then?