Since .NET has a garbage collector why do we need finalizers/destructors/dispose-pattern?

前端 未结 12 1640
粉色の甜心
粉色の甜心 2020-12-07 09:09

If I understand correctly the .net runtime will always clean up after me. So if I create new objects and I stop referencing them in my code, the runtime will clean up those

12条回答
  •  醉话见心
    2020-12-07 10:03

    Because the the Garbage Collector cannot collect what the managed environment did not allocate. Therefore any call to an unmanaged API that results in a memory allocation needs to be collected in the old fashioned way.

提交回复
热议问题