Anatomy of a “Memory Leak”

后端 未结 15 1341
失恋的感觉
失恋的感觉 2020-11-29 14:41

In .NET perspective:

  • What is a memory leak?
  • How can you determine whether your application leaks? What are the effects?
  • How can you prevent a
15条回答
  •  情歌与酒
    2020-11-29 15:32

    Also keep in mind that .NET has two heaps, one being the large object heap. I believe objects of roughly 85k or larger are put on this heap. This heap has a different lifetime rules than the regular heap.

    If you are creating large memory structures (Dictionary's or List's) it would prudent to go lookup what the exact rules are.

    As far as reclaiming the memory on process termination, unless your running Win98 or it equivalents, everything is released back to the OS on termination. The only exceptions are things that are opened cross-process and another process still has the resource open.

    COM Objects can be tricky tho. If you always use the IDispose pattern, you'll be safe. But I've run across a few interop assemblies that implement IDispose. The key here is to call Marshal.ReleaseCOMObject when you're done with it. The COM Objects still use standard COM reference counting.

提交回复
热议问题