Are memory leaks possible in managed environments

2019-02-12 22:25发布

In C++ it is easily possible to have a permanent memory leak - just allocate memory and don't release it:

new char; //permanent memory leak guaranteed

and that memory stays allocated for the lifetime of the heap (usually the same as program runtime duration).

Is the same (a case that will lead to a specific unreferenced object never been released while memory management mechanisms are working properly) possible in a C# program?

I've carefully read this question and answers to it and it mentions some cases which lead to getting higher memory consumption than expected or IMO rather extreme cases like deadlocking the finalizer thread, but can a permanent leak be formed in a C# program with normally functioning memory management?

7条回答
太酷不给撩
2楼-- · 2019-02-12 23:25

It's not exactly a memory leak, but if you're communicating with hardware drivers directly (i.e. not through a properly-written .net extension of a set of drivers) then it's fairly possible to put the hardware into a state where, although there may or may not be an actual memory leak in your code, you can no longer access the hardware without rebooting it or the PC...

Not sure if this is a useful answer to your question, but I felt it was worth mentioning.

查看更多
登录 后发表回答