简体   繁体   中英

How does the CLR find the classes which implement IDisposable?

I need some clarification on…

  1. … how the CLR — more specifically, the garbage collector — finds the classes which implement the IDisposable interface; and

  2. … how it calls the Dispose method (of all classes which implement the IDisposable interface) to free up memory?

The CLR does not call Dispose(), this is up to user code to call either directly or through the use of the using statement. The CLR will however call finalizers , although this is not gauranteed.

Dispose is not called automatically. The compiler generates calls to Dispose when you write using , or call Dispose directly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM