diff --git a/src/runtime/Finalizer.cs b/src/runtime/Finalizer.cs
index e796cacd1..f4b465ecb 100644
--- a/src/runtime/Finalizer.cs
+++ b/src/runtime/Finalizer.cs
@@ -106,6 +106,7 @@ internal IncorrectRefCountException(IntPtr ptr)
#endregion
+ [ForbidPythonThreads]
public void Collect() => this.DisposeAll();
internal void ThrottledCollect()
diff --git a/src/runtime/Native/NewReference.cs b/src/runtime/Native/NewReference.cs
index 25145fc4f..f7a030818 100644
--- a/src/runtime/Native/NewReference.cs
+++ b/src/runtime/Native/NewReference.cs
@@ -47,7 +47,7 @@ public PyObject MoveToPyObject()
///
public NewReference Move()
{
- var result = new NewReference(this);
+ var result = DangerousFromPointer(this.DangerousGetAddress());
this.pointer = default;
return result;
}
diff --git a/src/runtime/Runtime.cs b/src/runtime/Runtime.cs
index 20bef23d4..88a8ed173 100644
--- a/src/runtime/Runtime.cs
+++ b/src/runtime/Runtime.cs
@@ -359,6 +359,7 @@ static bool TryCollectingGarbage(int runs, bool forceBreakLoops)
///
/// Total number of GC loops to run
/// true if a steady state was reached upon the requested number of tries (e.g. on the last try no objects were collected).
+ [ForbidPythonThreads]
public static bool TryCollectingGarbage(int runs)
=> TryCollectingGarbage(runs, forceBreakLoops: false);
diff --git a/tests/test_constructors.py b/tests/test_constructors.py
index 6d8f00c12..3e0b1bb93 100644
--- a/tests/test_constructors.py
+++ b/tests/test_constructors.py
@@ -3,6 +3,7 @@
"""Test CLR class constructor support."""
import pytest
+import sys
import System
@@ -71,6 +72,19 @@ def test_default_constructor_fallback():
ob = DefaultConstructorMatching("2")
+def test_constructor_leak():
+ from System import Uri
+ from Python.Runtime import Runtime
+
+ uri = Uri("http://www.python.org")
+ Runtime.TryCollectingGarbage(20)
+ ref_count = sys.getrefcount(uri)
+
+ # check disabled due to GC uncertainty
+ # assert ref_count == 1
+
+
+
def test_string_constructor():
from System import String, Char, Array
diff --git a/version.txt b/version.txt
index b9eb748c0..dc72b3783 100644
--- a/version.txt
+++ b/version.txt
@@ -1 +1 @@
-3.0.0-rc3
+3.0.0-rc4