I am wondering if Binding gets released/collected by GC when Binding Mode is OneTime?
OneTime just presists the value of the source to target and thats it. Like its name says its just useful that one time. Therefore to me it would make sense that the Binding object should get thrown away.
I am not sure, how could I test this?
Reason why I ask this is I am maintaining a Binding in code behind with OneTime Mode and I would avoid all those approaches like clear methods, clear bindings, setting the target property to null, setting the Binding instance to null, setting all references to null... and all that when GC will "hopefully" collect it automatically anyways.
Any experiences on this?
OneTime just presists the value of the source to target and thats it. Like its name says its just useful that one time. Therefore to me it would make sense that the Binding object should get thrown away
If being more precise MSDN:
OneTime updates the target property only when the application starts
or when the DataContext undergoes a change.
This means that when changing DataContext property is also changing.
OneTime mode made for those properties that have not implemented INotifyPropertyChanged interface and not need notification property when he is updated. It is also done to prevent memory leaks that can occur when using Binding.
I think the garbage collector makes no exception for this mode, because if he removes it from memory prematurely, switch the DataContext don't updates the properties.
Some useful links
A memory leak may occur when you use data binding in Windows Presentation Foundation
Finding Memory Leaks in WPF-based applications
Can bindings create memory leaks in WPF?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With