# Feature or enhancement An API similar to: ``` /* Visit all live GC-capable objects, similar to gc.get_objects(None). * * Users should avoid allocating or deallocating objects on the Python heap in * the callback. */ typedef void (*gcvisitobjects_t)(PyObject *, void *); PyAPI_FUNC(void) PyGC_VisitObjects(gcvisitobjects_t callback, void *arg); ``` Which could be used as: ``` void count_functions(PyObject *op, void *arg) { if (PyFunction_Check(op)) { (*(int*)arg)++; } } int get_num_functions() { int count; PyGC_VisitObjects(count_functions, &count); return count; } ``` # Pitch We have a version of this in [Cinder](https://github.com/facebookincubator/cinder) already and right now and use it to [identify all generator objects so they can be de-opted when our JIT is shutdown](https://github.com/facebookincubator/cinder/blob/cinder/3.10/Jit/pyjit.cpp#L1871). In future we plan to use it for things like discovering existing PyFunction objects, and then using gh-91049 to mark them as JIT’able. This could facilitate loading the JIT feature at a later time (e.g. as part of a module). [Edited] In general, there already exists a Python API for iterating over GC’able objects via [gc.get_objects()](https://docs.python.org/3/library/gc.html#gc.get_objects), however there is no good way of doing this from native extensions. While it is technically possible to import the `gc` module and extract the `gc_objects` function in C this is cumbersome, and more importantly might lead to unexpected behavior if Python code has replaced the `gc_objects` function. <!-- gh-linked-prs --> ### Linked PRs * gh-102014 * gh-115560 <!-- /gh-linked-prs -->