Thanks for your question. I've reproduced the result you report here: https://github.com/rpoyner-tri/drake/pull/new/stack-overflow-leak-dev
Please check that branch and confirm it matches your experiment.
I'm not finished with my investigation yet, but I ran the test with VERBOSE = True
, and the (copious) output shows at least one thing I think is fishy. The MyAdder object is referred to by "bound methods". I'm not yet sure where they came from, but I suspect something in the intricate machinery of Python
inheritance from C++
base classes may be creating those.
So, if my hunch is right, the precise problem is "memory leaks involving leaf systems implemented in Python".
I'll continue poking at it, and update shortly.