This is pretty much just for me to make sure I'm right:
We have a resource class that implements the IDisposal template. It should (by design) be implemented in a way that allows it to receive a call more than once (even if we try to call it exactly once, of course). We also implement a finalizer that also calls the Dispose () method - just like backing up. If called manually, Dispose () will also call GC.SuppressFinalize (this).
There are several examples of removal schemes. Most of them call GC.SuppressFinalize (this) at the end of the delete code. Some argue that it would be better to name it at the beginning of the Dispose () method, before any cleanup. The latter argue that this will ensure that the GC does not call the finalizer at the same time while we are still cleaning.
Question:It seems that placing GC.SuppressFinalize at the beginning is not better? We still have a race condition, right? Is it true that we should instead implement Dispose () in streaming safe mode?
, , , , . GC.SuppressFinalize(this) 'this', , GC.SuppressFinalize. , , Dispose, , Dispose, - ( , - ) .
, , , . Microsoft . , . , ( ), , .
GC , .
, , - "", this . , dispose , .
this
, , SuppressFinalize .
SuppressFinalize
, CLR , / . "" , , - , , JIT, , .
.
- .
, Dispose , , , . , , .
microsoft GC.SuppressFinalize Dispose.
Source: https://habr.com/ru/post/1785857/More articles:How to get an array of object values using jquery - jqueryDirectX11 and Batch Kit - algorithmHow to make a panel draggable in Flex - flexДля петлевого вопроса в R - fileData line in SQL Server Denali - sql-serverElegantly change the list of variables: AddTo generalization, TimesBy, etc. - wolfram-mathematicaOpenMP and C99 data - cJQuery how to find the last child - jqueryInstall Microsoft loopback software switch from VBS (or C # / VB) - .netHow to install a device driver using C ++ on Win32? - c ++All Articles