Unity destructor Or OnDestory

来源:互联网 发布:vb和微信公众号对接 编辑:程序博客网 时间:2024/06/05 21:02

In 99% of all cases you don't want to use a destructor (finalizer) at all:

http://stackoverflow.com/questions/3649066/use-of-destructor-in-c
http://blog.stephencleary.com/2009/08/how-to-implement-idisposable-and.html

The destructor is called by the garbage collector which runs on a different thread. Custom managed classes never ever use a destructor unless you have unmanaged resources which need to be cleaned up. Never rely on a destructor to do something which should be in a manually called method. The destructor / finalizer in C# has nothing to do with a destructor in C++.

0 0