Side effects of garbage collection?

This may be a very close question, but I'm the type who sees what sticks to the wall. With all the benefits of memory and lifecycle management provided by garbage collection time collection, were there any noticeable cases of program uncertainty caused by race conditions between the application and the garbage collector? Has there been a gestalt of defensive programming against this kind of thing? Of course, programmers accustomed to RAII should learn lessons when in the presence of GC.

+3
source share
4 answers

The problem with garbage collection is that it manages memory resources. Unfortunately, programmers have to manage many, many other types of resources:

  • socket files and descriptors
  • database connections
  • synchronization objects
  • gui resources

to name just a few. To successfully deal with this, you really need the concepts embodied in the RAII idiom.

+7
source

I think you misunderstand how automatic garbage collection works. Race conditions between the application and a properly implemented garbage collector are impossible, even in principle. The garbage collector collects only those objects that the application cannot access.

Since only one of them can β€œown” this object, race conditions cannot occur.

+6

.NET , GC, , , .

, ! , - .Dispose(). ++, ...; -)

++, ! - ? , # 10 , ++. : , . , , .NET(# ++/CLI) 10 , ++ MFC: ++ .

, , .

+5

C, malloc realloc, , . , . ...

, , C, - , . . , ass'd.

Java #. , , , , . , Java Swing ( ), .

, , , GUI , . , . , .

EDIT:

. , . IMO

0

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


All Articles