Will ignoring IDisposable cause memory leaks?

前端 未结 7 1339
攒了一身酷
攒了一身酷 2021-01-02 02:04

In the comments to an answer I wrote we had a discussion about memory leaks and IDisposable where we didn\'t come to any real conclusion.

A class that h

7条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-02 02:27

    If an IDisposable object has a finalizer that de-allocates unmanaged memory then the memory will be free when the finalizer is called (after it is marked for collection by the GC and placed in the finalizer queue), but if there isn't any finalizer and Dispose() is never called, then memory can be leaked and only re-claimed when the process terminates.

提交回复
热议问题