的WeakReference和事件处理 [英] WeakReference and event handling

查看:174
本文介绍了的WeakReference和事件处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它是实现事件通过WeakReference的处理,如果该事件是唯一控股的参考,而我们需要的对象作为垃圾进行回收一个好的做法呢?

Is it a good practice to implement event handling through WeakReference if that event is the only thing holding the reference and that we would need the object to be garbage collected?

作为参数传递给这样的:

As an argument to this:

乡亲们说,如果你订阅的东西是你的责任,退订,你应该这样做。

Folks say that if you subscribe to something it’s your responsibility to unsubscribe and you should do it.

推荐答案

这是好事,得到来自退订的事件时,你可以的习惯,但有时没有一个明显的清理的方法在这里是可以做到的。我们最近发布了关于这个问题的一个博客文章;它包括方法,可以轻松订阅了WeakReference的事件。

It is good to get in the habit of unsubscribing from events when you can, but sometimes there isn't an obvious "cleanup" method where it can be done. We recently posted a blog article on this subject; it includes methods that make it easy to subscribe to an event with a WeakReference.

这篇关于的WeakReference和事件处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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