Skip to content

Commit 924e847

Browse files
committed
fixed leak in NewReference.Move
fixes #1872
1 parent 59b1c51 commit 924e847

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/runtime/Native/NewReference.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public PyObject MoveToPyObject()
4747
/// </summary>
4848
public NewReference Move()
4949
{
50-
var result = new NewReference(this);
50+
var result = DangerousFromPointer(this.DangerousGetAddress());
5151
this.pointer = default;
5252
return result;
5353
}

tests/test_constructors.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""Test CLR class constructor support."""
44

55
import pytest
6+
import sys
67

78
import System
89

@@ -71,6 +72,18 @@ def test_default_constructor_fallback():
7172
ob = DefaultConstructorMatching("2")
7273

7374

75+
def test_constructor_leak():
76+
from System import Uri
77+
from Python.Runtime import Runtime
78+
79+
uri = Uri("http://www.python.org")
80+
Runtime.TryCollectingGarbage(4)
81+
ref_count = sys.getrefcount(uri)
82+
83+
assert ref_count == 1
84+
85+
86+
7487
def test_string_constructor():
7588
from System import String, Char, Array
7689

0 commit comments

Comments
 (0)