Why are RAII and garbage collection mutually exclusive?

While I think I understand the essence of the problem (i.e. a good GC keeps track of objects , not the area ), I don’t know enough about the subject to convince others.

Can you give me an explanation why there are no garbage collectors with deterministic destructors?

+5
source share
3 answers

They are NOT mutually exclusive. Feel free to use C ++ with libgc (Boehm-Reiser-Detlefs collector). You can still use RAII, smart pointers, and manual deletion, but when you start GC, you can also just “forget” to delete some objects.

@ Indie's answer is that resources that are too late miss an important point: this is not a resource allocation release that is semantically critical, but rather a release order.

The reason GC does not seek to streamline the release is because ordering sorting is required to streamline requirements (dependencies) and an expensive algorithm.

Ocaml GC , . , , ( : ). .

+3

Wikipedia, , :

. , , , ( if), .

, RAII, , .

, , Java " " ( 6 " Java" ). " ".

0

( , ), . . , , (, ) GC , , . ... ( , ) GC , "GC ", - .

Thus, the GC and deterministic cleaning are mutually exclusive, since the GC does all the cleaning, and it cannot afford to determine, but must rely on maximizing its effectiveness.

0
source

All Articles