C#.NET测试内存泄漏.快速提问! [英] C#.NET testing for memory leaks. Quick question!

查看:77
本文介绍了C#.NET测试内存泄漏.快速提问!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试内存泄漏.我要让我的程序长时间发布(向缓存添加字符串)/读取(从缓存中删除字符串)一段时间,以查看内存是否累积或达到一定的学习量.

因此,我正在从System.GC.GetTotalMemory()检查总内存,以查看我正在使用多少内存.

但是我不知道是否应该将其设置为true或false,以允许该方法等待垃圾回收.

我该怎么办?还有其他测试内存泄漏或系统资源泄漏的好方法吗?

I am testing for memory leaks. I am going to let my program post(adds string to cache)/read(delete string from cache) for a long period of time to see if the memory accumulates or becomes study at a certain amount.

So I am checking the totalmemory from the System.GC.GetTotalMemory() to see how much memory I am using.

But I don''t know if I should set it to true or false to allow the method to wait for garbage collection.

Which should I do? Also is there other good ways to test for memory leaks, or system resource leaks?

推荐答案

您正在做的事情不会给您准确的结果.您必须使用分析器来执行此操作和/或使用PerfMon(性能监视器)和.NET Framework内存计数器来获取此数据.您可以通过单击开始->找到PerfMon.运行->键入Perfmon.msc.
What you''re doing will not give you accurate results. You have to use a profiler to do that and/or PerfMon (Performance Monitor) and the .NET Framework memory counters to get this data. You can find PerfMon by clicking on Start -> Run -> type Perfmon.msc.


但是,如果要使用GetTotalMemory方法,则仍然可以.我想您应该允许完全垃圾收集,因为您想知道是否忘记释放某些对象(它可能由您释放,但由于等待适当的时间而没有被GC释放),而不是垃圾收集器是否将其释放到此刻.
But still, if you want to use GetTotalMemory method. I think you should allow full garbage collection, since you are want to know whether you forgot to free some objects (it maybe freed by you, but not by GC, since it waits for appropriate moment), and not whether garbage collector freed it to this moment.


这篇关于C#.NET测试内存泄漏.快速提问!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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