3 ms·
Ugh... No. That's not how Python's GC works. Python is reference counted. This was happening because you didn't increment the reference count for python object
by winstonewert 10y ago
Ugh... No. That's not how Python's GC works.
Python is reference counted. This was happening because you didn't increment the reference count for python objects you were referencing from C++. Your RAII should increment/decrement reference counts on the object, not place objects into a global dict. That's the "correct" way to reference python objects.
Python's GC doesn't scan memory in the same way other languages do. Instead, it detects cycles between python objects. As long as you follow the reference counting rules correctly, you shouldn't have to worry about it. (Unless you need to detect cycles involving your C++ objects.)
- stinos 10y agoUgh... No. That's not how Python's GC works. You assume CPython, or some other reference counted implementation though. I'm talking about MicroPython which uses mark&sweep. And which I obviously should have mentioned but I guess I was tired and I didn't.