Will ignoring IDisposable cause memory leaks?

前端 未结 7 1314
攒了一身酷
攒了一身酷 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:50

    Just to add a little to Henk and Joel's answers

    What you've described happens quite often on DB Connections specifically. Enough that the ADO.NET Performance counter NumberOfReclaimedConnections got added. This counter tracks...

    The number of connections that have been reclaimed through garbage collection where Close or Dispose was not called by the application. Not explicitly closing or disposing connections hurts performance.

    The performance hit is usually a longer then necessary wait for a connection to be freed up. This can also result in timeouts on the connection, not a memory problem.

提交回复
热议问题