Skip to content

Commit 58e39a8

Browse files
committed
[PyROOT] Add regression test for #15703
1 parent 3d20650 commit 58e39a8

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

bindings/pyroot/pythonizations/test/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,6 @@ endif()
191191

192192
# TComplex pythonizations
193193
ROOT_ADD_PYUNITTEST(pyroot_tcomplex tcomplex_operators.py)
194+
195+
# Tests with memory usage
196+
ROOT_ADD_PYUNITTEST(pyroot_memory memory.py)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import gc
2+
import ROOT
3+
import unittest
4+
5+
6+
class MemoryStlString(unittest.TestCase):
7+
8+
def test_15703(self):
9+
"""Regression test for https://github.com/root-project/root/issues/15703"""
10+
11+
ROOT.gInterpreter.Declare("""
12+
#include <string>
13+
class foo {
14+
public:
15+
const std::string leak (std::size_t size) const {
16+
std::string result;
17+
result.reserve(size);
18+
return result;
19+
}
20+
};
21+
22+
auto get_rss_MB() {
23+
ProcInfo_t info;
24+
gSystem->GetProcInfo(&info);
25+
return info.fMemResident;
26+
}
27+
""")
28+
obj = ROOT.foo()
29+
for _ in range(1000000):
30+
__ = obj.leak(2048)
31+
32+
gc.collect()
33+
34+
before = ROOT.get_rss_MB()
35+
36+
for _ in range(1000000):
37+
__ = obj.leak(2048)
38+
39+
gc.collect()
40+
after = ROOT.get_rss_MB()
41+
delta = after - before
42+
self.assertLess(delta, 4)
43+
44+
45+
if __name__ == '__main__':
46+
unittest.main()

0 commit comments

Comments
 (0)