Demonstrate that this is not a bug

This commit is contained in:
Aaron Gokaslan 2021-08-29 14:26:43 -04:00
parent c019ea4516
commit 3602e5eb52

View File

@ -306,13 +306,13 @@ TEST_CASE("Reload module from file") {
class TestObject { class TestObject {
public: public:
TestObject(std::function<void()> f) : _id(++_count), _f(f) {} TestObject(std::function<void()> f) : _id(++_count), _f(std::move(f)) {}
~TestObject() { ~TestObject() {
py::print("~TestObject(" + std::to_string(_id) + ")");
--_count; --_count;
py::print("~TestObject(" + std::to_string(_id) + ")");
} }
int GetCount() { return _id; } int GetCount() const { return _id; }
static int _count; static int _count;
int _id; int _id;
@ -337,6 +337,7 @@ from test_memory_leak import TestObject
guard = TestObject(lambda: None) guard = TestObject(lambda: None)
)", local, local); )", local, local);
REQUIRE(1 == TestObject::_count); REQUIRE(1 == TestObject::_count);
local.clear();
} }
py::finalize_interpreter(); py::finalize_interpreter();