Should one call Dispose for Process.GetCurrentProcess()?

For example, see

How to get the current ProcessID?

No one bothered to call Dispose for an object returned by System.Diagnostics.Process.GetCurrentProcess() . Should it actually be called? Please explain why.


Yes, and actually it is important too. If you see the actual source, you will see the Dispose isn't just inherited from Component , it does something too.

It seems to me, looking at that code, that it is most important when EnableRaisingEvents is set to true , since that involves creating a wait handle. That handle needs to be released in order to prevent memory and handle leaking.

链接地址: http://www.djcxy.com/p/83170.html

上一篇: 获取Windows用户显示名称的可靠方法

下一篇: 应该为Process.GetCurrentProcess()调用Dispose吗?