Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5e041af

Browse files
committed
on runtime shutdown from Python release all slot holders, not only the ones, that belong to managed types
1 parenteec30c0 commit5e041af

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
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
internalstaticvoidRemoveTypes()
5353
{
54-
foreach(vartypeincache.Values)
54+
if(Runtime.HostedInPython)
5555
{
56-
if(Runtime.HostedInPython
57-
&&_slotsHolders.TryGetValue(type,outvarholder))
56+
foreach(varholderin_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(vartypeincache.Values)
68+
{
6669
type.Dispose();
6770
}
6871
cache.Clear();
@@ -507,7 +510,7 @@ internal static PyType CreateMetaType(Type impl, out SlotsHolder slotsHolder)
507510
{
508511
throwPythonException.ThrowLastAsClrException();
509512
}
510-
513+
511514
BorrowedReferencedict=Util.ReadRef(type,TypeOffset.tp_dict);
512515
using(varmod=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
internalstaticSlotsHolderCreateSlotsHolder(PyTypetype)
728731
{
732+
type=newPyType(type);
729733
varholder=newSlotsHolder(type);
730734
_slotsHolders.Add(type,holder);
731735
returnholder;

‎src/runtime/Types/ModuleObject.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,6 @@ public static Assembly AddReference(string name)
542542
/// <returns>The Type object</returns>
543543

544544
[ModuleFunction]
545-
[ForbidPythonThreads]
546545
publicstaticTypeGetClrType(Typetype)
547546
{
548547
returntype;

‎tests/test_engine.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,7 @@ def test_run_string():
4141
assertsys.multiline_worked==1
4242

4343
PythonEngine.ReleaseLock()
44+
45+
deftest_leak_type():
46+
importclr
47+
sys._leaked_intptr=clr.GetClrType(System.IntPtr)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp