File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed
Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,22 @@ public static void LoadSpecificArgs()
4646 }
4747 }
4848
49+ // regression test for https://github.com/pythonnet/pythonnet/issues/1561
50+ [ Test ]
51+ public void ImportClassShutdownRefcount ( )
52+ {
53+ PythonEngine . Initialize ( ) ;
54+
55+ PyObject ns = Py . Import ( typeof ( ImportClassShutdownRefcountClass ) . Namespace ) ;
56+ PyObject cls = ns . GetAttr ( nameof ( ImportClassShutdownRefcountClass ) ) ;
57+ ns . Dispose ( ) ;
58+
59+ Assert . Less ( cls . Refcount , 256 ) ;
60+
61+ PythonEngine . Shutdown ( ) ;
62+ Assert . Greater ( cls . Refcount , 0 ) ;
63+ }
64+
4965 /// <summary>
5066 /// Failing test demonstrating current issue with OverflowException (#376)
5167 /// and ArgumentException issue after that one is fixed.
@@ -182,4 +198,6 @@ public static void TestRunExitFuncs()
182198 Assert . True ( called ) ;
183199 }
184200 }
201+
202+ public class ImportClassShutdownRefcountClass { }
185203}
Original file line number Diff line number Diff line change @@ -67,7 +67,6 @@ internal static void DisposePythonWrappersForClrTypes()
6767 // since others may still referencing it.
6868 cls . CallTypeTraverse ( TraverseTypeClear , visitedPtr ) ;
6969 cls . CallTypeClear ( ) ;
70- cls . DecrRefCount ( ) ;
7170 }
7271 }
7372 finally
You can’t perform that action at this time.
0 commit comments