Open sophiehourihane opened 5 months ago
Python's memory allocator uses arena's, so PyObject
s are re-used. If a pointer is kept somewhere to a Python object that has been recycled, that will appear as such a type (and payload) change.
Just based on the limited code above, it's hard to guess what is what, but is modelCollection
perhaps pointing to a member of cold_chain
(both on the C++ side)?
Apologies for not having a reproducer.
I was wondering what the best practices are for using python_owns and how careful I should be with python's del operator. I am running into a slew of issues when I am testing my code which involves creating and destroying a bunch of cppyy objects. It seems that I am getting segfaults on garbage collection. I have tried manually controlling ownership via setting `python_owns`.
Unfortunately my tests rarely (if ever) fail when they are run alone, but when run with all the other tests they will fail. I think this points to memory issues.
I consistently get segfaults however during garbage collection like this:
Also, if I repeat tests by just having one test over an over again sometimes what will happen is that the type will be completely wrong despite the fact it is getting made in the exact same way. Here is code :
And this code usually works, (as in the first output below) but modelCollection will sometimes be a totally wild type instead:
I can try to be more specific if need be. I think it is an issue with the way the memory manager works.