I'm calling iteratively functions from embedded python. The functions share few common sympy expressions from a closure above them on which the function do subs() and solve(). The environment variable SYMPY_USE_CACHE does not work for me. I have to manually clean the cache. Even with that I still get the memory leak which I confirmed on Python side with empty def function(*args): return 0. Investigation with guppy showed that most of the memory consists of:
[Set of 266944 <mixed> objects. Total size = 72143480 bytes.
Index Size % Cumulative % Brief
0 1684 0.0 1684 0.0 sympy.core.assumptions.StdFactKB: 0x701a750
1 532 0.0 2216 0.0 sympy.core.assumptions.StdFactKB: 0x701a620
2 532 0.0 2748 0.0 sympy.core.assumptions.StdFactKB: 0x701a9b0
3 532 0.0 3280 0.0 sympy.core.assumptions.StdFactKB: 0x701aa48
4 532 0.0 3812 0.0 sympy.core.assumptions.StdFactKB: 0x701aae0
5 532 0.0 4344 0.0 sympy.core.assumptions.StdFactKB: 0x701ad40
6 532 0.0 4876 0.0 sympy.core.assumptions.StdFactKB: 0x7057a48
7 532 0.0 5408 0.0 sympy.core.assumptions.StdFactKB: 0x7057ca8
8 532 0.0 5940 0.0 sympy.core.assumptions.StdFactKB: 0x7057d40
9 532 0.0 6472 0.0 sympy.core.assumptions.StdFactKB: 0x7057dd8