| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -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; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -542,7 +542,6 @@ public static Assembly AddReference(string name) | |||
| 542 | 542 | /// <returns>The Type object</returns> | |
| 543 | 543 | ||
| 544 | 544 | [ModuleFunction] | |
| 545 | - [ForbidPythonThreads] | ||
| 546 | 545 | public static Type GetClrType(Type type) | |
| 547 | 546 | { | |
| 548 | 547 | return type; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,3 +41,7 @@ def test_run_string(): | |||
| 41 | 41 | assert sys.multiline_worked == 1 | |
| 42 | 42 | ||
| 43 | 43 | PythonEngine.ReleaseLock() | |
| 44 | + | ||
| 45 | + def test_leak_type(): | ||
| 46 | + import clr | ||
| 47 | + sys._leaked_intptr = clr.GetClrType(System.IntPtr) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments