What are the most common (and often overlooked) causes of memory leaks in managed (.net) applications?

后端 未结 11 970
闹比i
闹比i 2021-02-04 09:32

Please can anyone recommend a quick checklist / best practice guide to help us avoid simple (but subtle) mistakes that cause could cause memory leaks in .net apps

I find

11条回答
  •  遥遥无期
    2021-02-04 10:01

    Memory leaks can come from a variety of sources.

    • You registered an event but forgot to unregister that event.

    • Files/connections were opened but not closed properly.

    • The Dispose() call was not implemented properly.

    • The Dispose() call was bypassed somehow; for example, an exception was encountered in between.

    • You encountered a deadlock (which may result in not releasing root objects).

    • The finalizer thread is blocked; for example, the STA thread for the COM object is not available.

    • There are leaks from unmanaged code.

    • An object’s lifetime is too high.

    • There is a circular reference.

    • Leaks can come from the .NET Runtime environment (on rare occasions).

    • Leaks may also appear from your testing framework. (In that case, it is a test leak, not a development environment leak, and test engineers are responsible for resolving it.)

提交回复
热议问题