内存泄漏.NET 2.0 [英] Memory leak .NET 2.0

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

问题描述





是否可以在Windows应用程序运行过程中释放所有非托管资源,

我正在运行一个C#.NET 2.0应用程序导致问题。



谢谢,

Shreyas

Hi,

Is it possible to free all unmanaged resources in the middle of the windows application run,
I'm running a C#.NET 2.0 application as it is causing an issue .

Thanks,
Shreyas

推荐答案

如果你问的是如何清理你在应用程序中间做错的事情,那么不,你不能。好吧,不是没有退出你的应用程序并再次启动它。



原因是你因为通过让它们指针丢失而孤立它们而泄漏了资源没有正确处理它们的范围。



真正的解决方案是识别泄漏,为什么会发生泄漏(提示:你没有做某事)正确)并修改代码以便在自身之后正确清理。
If you're asking how to clean up thing you've done wrong in the middle of the application, then NO, you can't. Well, not without quitting your application and launching it again.

The reason being is that you're leaking resources because you orphaned them by letting the pointer to them drop out of scope without properly disposing them in the first place.

The REAL solution to this is to identify the leak, why it's occurring (HINT: YOU didn't do something correctly) and modifying the code to properly clean up after itself.


只有当你设计使用非托管资源时才这样。但我认为这将是困难的,毫无意义。合理的做法是在您不需要资源时立即释放资源。所有使用非托管资源的.NET FCL类都是这样设计的。



-SA
Only if you design the use of your unmanaged resources that way. But I think it would be difficult and totally pointless. The reasonable practice is to free the resources as soon as you don't need them. All .NET FCL classes are using unmanaged resources are designed this way.

—SA


是的,这是可能的,但我会考虑你何时以及如何释放这些资源。要正确释放资源,一个好方法是实现 IDisposable 接口。



参见这个 [ ^ ]页面上有一个很好的例子。



祝你好运!

Eduard
Yes this is possible, I would however consider when and how you release those resources. To correctly free the resources one good way is to have the IDisposable interface implemented.

See this[^] page for an excellent example.

Good luck!
Eduard


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

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