Skip to content

Commit e5814fd

Browse files
committed
prevent ref cycle
1 parent f4bc8ee commit e5814fd

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/duckdb_py/pyconnection.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,9 @@ shared_ptr<DuckDBPyConnection> DuckDBPyConnection::ExecuteMany(const py::object
527527
}
528528
// Set the internal 'result' object
529529
if (query_result) {
530-
auto py_result = make_shared_ptr<DuckDBPyResult>(std::move(query_result));
531-
con.SetResult(CreateRelation(std::move(py_result)));
530+
// Don't use CreateRelation here — the result is stored inside the connection,
531+
// so setting connection_owner would create a ref cycle (connection → result → connection).
532+
con.SetResult(make_uniq<DuckDBPyRelation>(make_shared_ptr<DuckDBPyResult>(std::move(query_result))));
532533
}
533534

534535
return shared_from_this();
@@ -727,8 +728,9 @@ shared_ptr<DuckDBPyConnection> DuckDBPyConnection::Execute(const py::object &que
727728

728729
// Set the internal 'result' object
729730
if (res) {
730-
auto py_result = make_shared_ptr<DuckDBPyResult>(std::move(res));
731-
con.SetResult(CreateRelation(std::move(py_result)));
731+
// Don't use CreateRelation here — the result is stored inside the connection,
732+
// so setting connection_owner would create a ref cycle (connection → result → connection).
733+
con.SetResult(make_uniq<DuckDBPyRelation>(make_shared_ptr<DuckDBPyResult>(std::move(res))));
732734
}
733735
return shared_from_this();
734736
}

0 commit comments

Comments
 (0)