Skip to content

Commit 5aa82ea

Browse files
committed
on runtime shutdown from Python release all slot holders, not only the ones, that belong to managed types
1 parent eec30c0 commit 5aa82ea

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/runtime/TypeManager.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,21 @@ internal static void Initialize()
5151

5252
internal static void RemoveTypes()
5353
{
54-
foreach (var type in cache.Values)
54+
if (Runtime.HostedInPython)
5555
{
56-
if (Runtime.HostedInPython
57-
&& _slotsHolders.TryGetValue(type, out var holder))
56+
foreach (var holder in _slotsHolders)
5857
{
5958
// If refcount > 1, it needs to reset the managed slot,
6059
// otherwise it can dealloc without any trick.
61-
if (Runtime.Refcount(type) > 1)
60+
if (holder.Key.Refcount > 1)
6261
{
63-
holder.ResetSlots();
62+
holder.Value.ResetSlots();
6463
}
6564
}
65+
}
66+
67+
foreach (var type in cache.Values)
68+
{
6669
type.Dispose();
6770
}
6871
cache.Clear();
@@ -507,7 +510,7 @@ internal static PyType CreateMetaType(Type impl, out SlotsHolder slotsHolder)
507510
{
508511
throw PythonException.ThrowLastAsClrException();
509512
}
510-
513+
511514
BorrowedReference dict = Util.ReadRef(type, TypeOffset.tp_dict);
512515
using (var mod = Runtime.PyString_FromString("clr._internal"))
513516
Runtime.PyDict_SetItemString(dict, "__module__", mod.Borrow());
@@ -726,6 +729,7 @@ internal static void CopySlot(BorrowedReference from, BorrowedReference to, int
726729

727730
internal static SlotsHolder CreateSlotsHolder(PyType type)
728731
{
732+
type = new PyType(type);
729733
var holder = new SlotsHolder(type);
730734
_slotsHolders.Add(type, holder);
731735
return holder;

0 commit comments

Comments
 (0)