Keep GC from collecting when an object goes out of scope (user_c_module) #17711
Unanswered
kdschlosser
asked this question in
Using MicroPython
Replies: 1 comment
-
See Alternatively, attach your callback function to a variable that's at module scope; the module's global table will hang on to it.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am writing a user c module where I need to have a python callback function passed to a function that is in a user c module and I would like to know if there is a way to keep the the callback function from getting garbage collected if it goes out of scope.
as an example..
the issue is that once
some_function
exists thecallback_function
object gets collected by the GC even tho it has been passed to another function and stored in C code to be used at a later time. If there a way to stopcallback_function
from being marked for deletion and being collected by the GC? I would think that there is some kind of a reference counter that is able to be incremented if a function gets passed and it would need to be decremented if the c object holding reference to it gets deleted or the function no longer used.any help with this would be greatly appreciated.
Beta Was this translation helpful? Give feedback.
All reactions