wlav / cppyy

Other
412 stars 42 forks source link

std::list leaks memory while std::vector does not #245

Open saraedum opened 4 months ago

saraedum commented 4 months ago

The following quickly eats through my RAM:

import cppyy
cppyy.cppdef(r"""
#include <list>
std::list<int> f() { return std::list<int>(3); }
""")
while True: _ = list(cppyy.gbl.f())

However, if I replace list with vector, memory consumption is stable.


This is with cppyy 3.1.2 from conda-forge on x86_64 Arch Linux.

saraedum commented 4 months ago

Same with a pip installed cppyy 3.1.2.

wlav commented 12 hours ago

Fixed in repo (and leak check test added). The reason for the difference between list and vector is that std::vector has its own ("high performance") iterator. The cause was an incorrect lifeline direction (causing a circular dependency) in the generic STL iterator protocol, which was unnecessary anyway b/c the iterator pythonization already added a lifeline.