Which objects can I use in a finalizer method?

前端 未结 3 510
我在风中等你
我在风中等你 2020-12-03 08:14

I have a class that should delete some file when disposed or finalized. Inside finalizers I can\'t use other objects because they could have been garbage-collected already.<

3条回答
  •  一个人的身影
    2020-12-03 08:51

    You can call the dispose method inside your finalizer and have the file cleanup code in the Dispose method. Along with that you can also pass a boolean to your dispose method that indicates that you are invoking it from the finalizer.

    For an excellent reference on the proper usage of Dispose and Fianlizers , read this Proper use of the IDisposable interface

提交回复
热议问题