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

前端 未结 12 1613
粉色の甜心
粉色の甜心 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 09:54

    Mainly for non-managed code, and interaction with non-managed code. "Pure" managed code should never need a finalizer. Disposable on the other hand is just a handy pattern to force something to be released when you are done with it.

提交回复
热议问题