C # - free up your own resources

I am relatively new to .net. Since I was trying to understand the concept of Garbage Collection (from "CLR via C #"), I found out how strong the garbage collection approach is. But then, while reading, I realized that the allocated resources should be released. Methods:
i) Creating our type comes from CriticalFinalizerObject type
ii) Using the Dispose Pattern by an operator using

Questions in my mind:
1) I'm a little confused when to use what? 2) Is it also harder for the CLR to move objects that do not contain garbage to compress the heap?

3) Any other sentence of the article for a deeper understanding and understanding of the concept.

Please correct me if I am mistaken in any of the above statements
Regards,
Justin Samuel.

+3
source share
4 answers
  • You want to get CriticalFinalizerObjectone if your type should be considered a restricted execution area or CER for short. CER is a region of code that should be populated without exception, and in my experience they are often not used, but this does not mean that they are not useful.

    IDisposable - , . (, ).

  • , , , . , , , , . ​​ , , , .

  • , , CLR # - , .

+4

Dispose, Finalization Resource Management.

, , , . , :

  • , , , IDisposable .
  • Basic Dispose Pattern ( ), , IDisposable.
  • CriticalFinalizerObject.

.

+3

Dispose using, . , , . , , , , - .

- . CLR, , . , CS : .

+2

() . , ThreadAbort OutOfMemory . .

CriticalFinalizerObject , , "" , . SafeHandle CriticalFinalizerObject . , , , , , , ThreadAbortException.

() IDisposable

using(), IDisposable - . using(), . .

, CriticalFinalizerObject , , , using() - . .

using() , , , Dispose() .

GC

Compaction of the heap can be more efficient because objects that remain for a long time in the end are packed together. In the NET Framework, only the lowest generation (most recently created objects) is compressed aggressively. Theres is a great optimization done under the hood. It is interesting to read, but not important for the job. If you want to know more about this, find articles on “generation garbage collection”.

0
source

Source: https://habr.com/ru/post/1722239/


All Articles