-
Notifications
You must be signed in to change notification settings - Fork 18k
runtime: Finalizer not called for parent variable #6268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
Comments
The garbage collector is not perfectly precise. It is conservative. That means that in some cases it will retain a block that is not really being referenced. There is ongoing work to improve this. I'm not sure why you are seeing a different result on tip than I am. I ran your test case on a GNU/Linux system. |
In what cases would this happen, even when runtime.GC() is called? I re-ran it on tip, and it's working now. Strange. I am having some odd results with cgo though that's causing the finalizer not to run. Specifically I have a C struct inside my Go struct, and when V8 does a TryCatch my Isolate finalizer isn't run. Still debugging this. |
Forgive me, but in quoting the docs: >If a cyclic structure includes a block with a finalizer, that cycle is not guaranteed to be garbage collected and the finalizer is not guaranteed to run, because there is no ordering that respects the dependencies. So if I don't have a cyclic structure, it should always run. > There is no guarantee that finalizers will run before a program exits, so typically they are useful only for releasing non-memory resources associated with an object during a long-running program. If I run runtime.GC, this runs the garbage collector before the program exits. With what I'm doing I don't have a cyclic structure, and the garbage collector is running before the program exits. So what else is not guaranteed, besides what is mentioned in the docs? I know I am having some weird behavior with cgo. |
@luke. runtime.GC() does not provide a guarentee that a finaliser will run. I can see how it could be construed that that if the object is not garbage collected the finaliser cannot run, however runtime.GC() does not currently guarentee that all memory that can be collected will be collected (see comment #3), and even if the memory was collected, it is not guarenteed that the finaliser will not be run, because no such guarentee is made. Please, let's not talk about runtime.GC has having anything to do with this issue. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: