Why call Dispose()? Memory leak won't occur?

前端 未结 7 727
无人及你
无人及你 2020-12-29 10:01

Edit: My question isn\'t getting the main answer that I was looking for. I wasn\'t clear. I would really like to know two things:

  1. Can NOT call
7条回答
  •  感情败类
    2020-12-29 10:33

    The convention is that if an object implements IDisposable you should call Dispose() or use the "using" pattern. The difference between Dispose() and waiting for the destructor (finalizer) to execute is that Dispose() is called right away and can be used for freeing some important resources like db connections, files, devices, unmanaged oejects, etc.

    So to summarize - if it is IDisposable - Dispose() it!

提交回复
热议问题