C#和System.GC.Collect() [英] c# And System.GC.Collect()

查看:419
本文介绍了C#和System.GC.Collect()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用ReportViewer时,它会占用大量内存!

when I Use ReportViewer it takes many Memory !
How Can I force memory cleanup in C#?

推荐答案

您真的不能. GC仅适用于MANAGED对象,而不适用于非托管(或基于COM)对象.您只需运行GC(不推荐使用!),该组件仍将占用所需的大量内存.
You really can''t. The GC only work on MANAGED objects, not unmanaged (or COM-based) objects. You run the GC all you want (NOT RECOMMENDED!) and the component is still going to take however much memory it wants.


您可以使用 GC.Collect()运行垃圾回收器.
但是,您无法控制何时真正从内存中清除reportviewer对象-这只能由垃圾收集器本身控制.
You can use GC.Collect() to run the garbage collector.
However, you cannot control when the reportviewer object will actually be cleared from memory - this can only be controlled by the garbage collector itself.


这篇关于C#和System.GC.Collect()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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