C#:WeakReference的通知之前收集? [英] C#: Notification before WeakReference is collected?

查看:140
本文介绍了C#:WeakReference的通知之前收集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#/。NET,有没有什么办法让一个通知之前指向的对象由弱引用被破坏?基本上,我想允许被收集的对象,但做一些合适的对象之前被销毁,而无需修改code添加析构函数(因为我不知道到底是什么类型的对象将与我的$ C被起诉$ C)。

In C#/.NET, is there any way to get a notification before the object pointed to by a weak reference is destructed? Basically, I want to allow an object to be collected, but do something right before the object is destroyed, without modifying code to add destructors (since I won't know exactly what types of objects will be sued with my code).

谢谢, 罗伯特·

推荐答案

您不能这样做。 但是你可以做的是,当GC将至看(还有在CLR v3.5Sp1,让你这样做,GCNotifications新的GC的API)

You can't do that. However what you can do is to watch when a GC is approaching ( there are new GC APIs in CLR v3.5Sp1 that allows you to do so, GCNotifications )

这篇关于C#:WeakReference的通知之前收集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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