Does calling `gc ()` manually make all finalizers execute immediately?

I have a code that I suspect is a memory leak. Because the code uses ccall and maintains significant information contained within pointers that should be freed by the code that ccall ed during finalizer s.

In my debugging, I call gc() . And I want to know if it will immediately trigger all finalizer that are bound to objects that are out of scope

Answers should concern only julie 0.5 +.

+5
source share
1 answer

After discussing @Isaiah's answer (deleted), I decided to push some internal people out and get some clarity on this. As a result, I have good confidence that when gc() is called at the top level , that is, not in the local area, you can rely on the following confidence:

if the object is unavailable and you call gc() itll be complete

which is pretty clear. The top-level part is significant because when you call gc() in the local scope, local links may or may not be considered accessible, even if they are never used again.

This certainty does sweep some uncertainty under the “reachability” carpet, as it may not be clear whether the object is reached or not, because the language runtime may contain references to some objects for various reasons. These reasons should be comprehensively documented, but currently they are not. Some great cases where the runtime holds objects:

  • A unique instance of a singleton type is permanent and will never be assembled or finalized;

  • The method’s cache is also constant, which, in particular, means that the modules are not freed if you would otherwise expect them to be, since the method cache stores references to the modules in which they are defined.

However, in “normal circumstances” - this is what I suspect - yes, calling gc() when the object is no longer available will lead to its collection and completion “immediately”, i.e. before gc() returns the call.

+4
source

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


All Articles