Finalizers with Dispose() in C#

前端 未结 2 2019
情歌与酒
情歌与酒 2021-01-06 03:45

See the code sample from MSDN: (http://msdn.microsoft.com/en-us/library/b1yfkh5e(v=VS.100).aspx)

// Design pattern for a base class.
public class Base: IDisp         


        
2条回答
  •  一向
    一向 (楼主)
    2021-01-06 04:25

    There are 2 scenarios:

    • Your code calls Dispose (preferred) and the Finalizer is canceled, eliminating the overhead.
    • Your code 'leaks' the object and the GC calls the Finalizer.

提交回复
热议问题