问题描述
我开始学习Windows Phone 8的LINQ-to-SQL
,并遇到了这篇在MSDN上的文章.
I am starting to learn LINQ-to-SQL
for Windows Phone 8, and came across this article on MSDN.
它们显示了实现INotifyPropertyChanging
和INotifyPropertyChanged
的DataContext
的基类. INotifyPropertyChanging
的原因是:
They show a base class for DataContext
which implements both INotifyPropertyChanging
and INotifyPropertyChanged
. The reasoning for the INotifyPropertyChanging
is:
◦INotifyPropertyChanging接口有助于限制内存消耗 与变更跟踪有关.
◦The INotifyPropertyChanging interface helps limit memory consumption related to change tracking.
本文未能提供任何具体参考来证明对INotifyPropertyChanging
接口的内存消耗的主张. INotifyPropertyChanging 上的文章本身只是说:
The article fails to give any specific references to justify the claim of memory consumption to the INotifyPropertyChanging
interface. The article on INotifyPropertyChanging itself just says:
有人可以告诉我这个接口如何限制应用程序的内存占用,仅通过通知属性值将要更改(甚至不限制更改不会发生)来实现吗?
Can someone please explain to me how this interface which limits the memory footprint of an application, just by notifying that a property value is about to change (and not even restricting that change to from happening)?
推荐答案
好吧,我终于找到了另一个 MSDN文章,该文章实际上解释了INotifyPropertyChanging
如何限制内存占用量.引用文章(重点是我的):
Okay, I finally found another MSDN article which actually explains how INotifyPropertyChanging
will limit memory footprint. Quoting the article (emphasis mine):
对于未实现INotifyPropertyChanging的对象,LINQ to SQL 保留对象首次实现时所具有的值的副本.
For objects that do not implement INotifyPropertyChanging, LINQ to SQL maintains a copy of the values that objects had when they were first materialized.
因此,如果您不实施INotifyPropertyChanging
并且从不更新使用Linq-SQL提取的任何对象,它仍将为它创建的每个对象创建该对象的副本.通过实现该接口,您可以避免额外的内存使用,并且仅当您实际上在更改对象状态时才让它创建副本.
So if you don't implement INotifyPropertyChanging
and never update any objects fetched using Linq-SQL, it will still create a copy of the object for every object it creates. By implementing the interface, you can avoid that additional memory usage, and have it create copies only when you actually are making a change to the object state.
这篇关于INotifyPropertyChanging接口如何帮助限制内存消耗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!