在.NET弱引用 [英] weak references in .net

查看:112
本文介绍了在.NET弱引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以给使用.NET项目弱引用的一些例子?

Can someone give some examples of using weak references in .net projects ?

推荐答案

想想有2级缓存。因此,在第一级的对象与正常引用,并在随后2级用弱引用引用。因此,如果你想从到期的1级的对象,你可以把它放在了第二级。

Think about cache with 2 levels. So objects in the 1st level are referenced with normal references and in then 2nd level with weak references. Thus if you want to expiry your object from the 1st level you can put it in the 2nd level.

下一次,当客户端尝试,如果你有足够的内存对象将从第2级提升为访问这个对象,但是如果内存不够和对象,收集你将不得不重新创建对象。有时它会被重新创建或从昂贵的存储库检索,但在某些情况下,你就可以找到它的第二级。

Next time, when client tries to access this object if you have enough memory object will be promoted from the 2nd level, however if memory is not enough and object was collected you will have to recreate your object. Sometimes it will be recreated or retrieved from expensive store but in some situation you will be able to find it in the 2nd level.

这篇关于在.NET弱引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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