如何强制对象的垃圾收集你不能提领? [英] How to force garbage collection of object you can't dereference?

查看:242
本文介绍了如何强制对象的垃圾收集你不能提领?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用的EWS托管API,它调查的MS Exchange对于一个给定的时间间隔后新邮件。随着轮询呼叫( PullSubscription.GetEvents())的每次调用 - 微软的API是未能妥善处理的NetworkStream 并导致内存比例增加。这是以前这里讨论过,但从来没有得到解决。 。使用蚂蚁探查我们能够确定哪些对象是在内存中不断发展壮大,找出问题

We are using EWS Managed API which polls MS Exchange for new mail messages after a given interval. With each invocation of the polling call (PullSubscription.GetEvents()) - Microsofts API is failing to properly dispose the NetworkStream and causes memory to proportionately increase. This was previously discussed here, but never resolved. Using ANTS Profiler we were able to determine which objects were continuously growing in memory and isolate the issue.

现在,这个问题已被隔离 - 是有办法处置在我们不必基准的外部API创建一个的NetworkStream?所以GC.Collect()似乎不处理它,因为它仍然具有积极的参考。我们可以做些什么来清理的晃来晃去的参考?有一些包装,我们可以用它来强迫马车SDK的清理?

Now that the issue has been isolated - is there a way to dispose of a NetworkStream created in an external API that we don't have a reference to? GC.Collect() doesn't seem to dispose it since it still has an active reference. What can we do to cleanup the dangling reference? Is there some wrapper we can use to force cleanup of their buggy SDK?

推荐答案

有没有办法强制GC来释放内存对于引用的对象!

There is no way to force GC to release memory for a referenced object!

首先,我建议联系微软本身对于这个bug帮助。

First of all I would suggest to contact microsoft itself for help with this bug.

第二,你说的是处置或只是内存释放?他们是两个完全不同的事情。 (IDisposable模式,终结)。

Second, are you talking about "disposal" or just memory release? They are two totally different things. (IDisposable pattern, finalizers).

三,可你只要解引用被引用这些对象的对象?

Third, can u just dereference the object that are referencing these objects?

第四,一个可能的解决方案可与反射器进行反编译的是给你的问题代码,了解一个方式,你可以到达那些保持引用对象的字段,使用反射在你的代码来访问私有字段,并把它们为null。
是一个非常肮脏的黑客,但如果你有没有其他的办法是我能想到的唯一的东西。这样做只是如果你不能以任何其他方式去了。

Fourth, one possible solution can be to decompile with reflector the code that is giving you the issue, understand a way you can arrive to the fields that are keeping the referenced objects, use reflection in your code to access the private fields and put them to null. Is a very dirty hack, but if you have no other way is the only thing i can think of. Do this only if you cannot go in any other ways.

这篇关于如何强制对象的垃圾收集你不能提领?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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