Insecure C # garbage collector

I read about a memory leak in managed code and wondered if this could be created in unsafe C # code?

unsafe { while(true) new int; } 

I was not sure if this would catch the GC if it worked as unsafe code?

thanks

+4
source share
2 answers

The unsafe keyword allows you to use unsafe code (pointers).

It does not change the semantics of regular code at all.

+10
source

IMO insecurely allows the use of pointer types and the generation of C ++ style styles in memory. But to tell the garbage collector not to touch my code, use the corrected operator.

C # supports direct memory manipulation through pointers in blocks with code marked insecurely and compiled with the / unsafe compiler option.

The fixed statement is used to tell the garbage collector not to touch this code, which has been rounded with the fixed statement.

  unsafe { fixed (int* a = &b) // tells garbage collector not touch { *a = 9; } } 
+5
source

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


All Articles