@@ -51,18 +51,21 @@ internal static void Initialize()
51
51
52
52
internal static void RemoveTypes ( )
53
53
{
54
- foreach ( var type in cache . Values )
54
+ if ( Runtime . HostedInPython )
55
55
{
56
- if ( Runtime . HostedInPython
57
- && _slotsHolders . TryGetValue ( type , out var holder ) )
56
+ foreach ( var holder in _slotsHolders )
58
57
{
59
58
// If refcount > 1, it needs to reset the managed slot,
60
59
// otherwise it can dealloc without any trick.
61
- if ( Runtime . Refcount ( type ) > 1 )
60
+ if ( holder . Key . Refcount > 1 )
62
61
{
63
- holder . ResetSlots ( ) ;
62
+ holder . Value . ResetSlots ( ) ;
64
63
}
65
64
}
65
+ }
66
+
67
+ foreach ( var type in cache . Values )
68
+ {
66
69
type . Dispose ( ) ;
67
70
}
68
71
cache . Clear ( ) ;
@@ -507,7 +510,7 @@ internal static PyType CreateMetaType(Type impl, out SlotsHolder slotsHolder)
507
510
{
508
511
throw PythonException . ThrowLastAsClrException ( ) ;
509
512
}
510
-
513
+
511
514
BorrowedReference dict = Util . ReadRef ( type , TypeOffset . tp_dict ) ;
512
515
using ( var mod = Runtime . PyString_FromString ( "clr._internal" ) )
513
516
Runtime . PyDict_SetItemString ( dict , "__module__" , mod . Borrow ( ) ) ;
@@ -726,6 +729,7 @@ internal static void CopySlot(BorrowedReference from, BorrowedReference to, int
726
729
727
730
internal static SlotsHolder CreateSlotsHolder ( PyType type )
728
731
{
732
+ type = new PyType ( type ) ;
729
733
var holder = new SlotsHolder ( type ) ;
730
734
_slotsHolders . Add ( type , holder ) ;
731
735
return holder ;
0 commit comments