INotifyPropertyChanging接口如何帮助限制内存消耗 [英] How does INotifyPropertyChanging interface helps limit memory consumption

查看:72
本文介绍了INotifyPropertyChanging接口如何帮助限制内存消耗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始学习Windows Phone 8的LINQ-to-SQL,并遇到了

I am starting to learn LINQ-to-SQL for Windows Phone 8, and came across this article on MSDN.

它们显示了实现INotifyPropertyChangingINotifyPropertyChangedDataContext的基类. INotifyPropertyChanging的原因是:

They show a base class for DataContext which implements both INotifyPropertyChanging and INotifyPropertyChanged. The reasoning for the INotifyPropertyChanging is:

◦INotifyPropertyChanged接口用于更改跟踪.

◦The INotifyPropertyChanged interface is used for change tracking.

◦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:

通知客户端属性值正在更改.

Notifies clients that a property value is changing.

有人可以告诉我这个接口如何限制应用程序的内存占用,仅通过通知属性值将要更改(甚至不限制更改不会发生)来实现吗?

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)?

推荐答案

好吧,我终于找到了另一个

Okay, I finally found another MSDN article which actually explains how INotifyPropertyChanging will limit memory footprint. Quoting the article (emphasis mine):

通知是通过属性设置器中的PropertyChanging事件提供的.当通知对象的第一次更改时,LINQ to SQL将创建对象的副本,并将该对象视为生成Update语句的候选对象.

Notifications are provided through the PropertyChanging event in property setters. When LINQ to SQL is notified of the first change to an object, it creates a copy of the object and considers the object a candidate for generating an Update statement.

对于未实现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接口如何帮助限制内存消耗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆