加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – INotifyPropertyChanging接口如何帮助限制内存消耗

发布时间:2020-12-15 07:48:01 所属栏目:百科 来源:网络整理
导读:我开始学习 Windows Phone 8的LINQ-to-SQL,并且在MSDN上遇到了 this篇文章. 它们显示了DataContext的基类,它实现了INotifyPropertyChanging和INotifyPropertyChanged. INotifyPropertyChanging的原因是: ?The INotifyPropertyChanged interface is used for
我开始学习 Windows Phone 8的LINQ-to-SQL,并且在MSDN上遇到了 this篇文章.

它们显示了DataContext的基类,它实现了INotifyPropertyChanging和INotifyPropertyChanged. INotifyPropertyChanging的原因是:

?The INotifyPropertyChanged interface is used for change tracking.

?The INotifyPropertyChanging interface helps limit memory consumption
related to change tracking.

本文未能提供任何特定的引用来证明INotifyPropertyChanging接口的内存消耗声明.关于INotifyPropertyChanging的文章本身就说:

Notifies clients that a property value is changing.

有人可以向我解释这个界面如何限制应用程序的内存占用,只需通知一个属性值即将发生变化(甚至不会限制该变化发生)?

解决方法

我只能推断,但我认为这是作者的想法:

在没有INotifyPropertyChanging的世界中,如果消费者需要属性的旧值,它必须抢先缓存它(因为,一旦引发了PropertyChanged事件,它就太晚了,值已经改变了).或者,生产者可以在不同的属性中保留旧值的副本.无论哪种方式,数据始终保持重复.

使用INotifyPropertyChanging,消费者不需要事先缓存任何内容.引发PropertyChanging事件时,它可以获取旧值,知道它将要更改.然后引发NotifyPropertyChanged事件,消费者可以获取新值,对两者执行任何操作,然后删除它们.数据仍然是重复的,但仅限于特定时间点和有限的持续时间.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读