Skip to content

Commit 0dee5da

Browse files
committed
Free GC handle for all subclass of ExtensionType
1 parent cad95da commit 0dee5da

File tree

8 files changed

+15
-10
lines changed

8 files changed

+15
-10
lines changed

src/runtime/constructorbinding.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public static IntPtr tp_repr(IntPtr ob)
145145
var self = (ConstructorBinding)GetManagedObject(ob);
146146
Runtime.XDecref(self.repr);
147147
Runtime.XDecref(self.pyTypeHndl);
148-
ExtensionType.FinalizeObject(self);
148+
self.Dealloc();
149149
}
150150

151151
public static int tp_traverse(IntPtr ob, IntPtr visit, IntPtr arg)
@@ -242,7 +242,7 @@ public static IntPtr tp_repr(IntPtr ob)
242242
var self = (BoundContructor)GetManagedObject(ob);
243243
Runtime.XDecref(self.repr);
244244
Runtime.XDecref(self.pyTypeHndl);
245-
FinalizeObject(self);
245+
self.Dealloc();
246246
}
247247

248248
public static int tp_traverse(IntPtr ob, IntPtr visit, IntPtr arg)

src/runtime/eventbinding.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public static IntPtr tp_repr(IntPtr ob)
118118
{
119119
var self = (EventBinding)GetManagedObject(ob);
120120
Runtime.XDecref(self.target);
121-
ExtensionType.FinalizeObject(self);
121+
self.Dealloc();
122122
}
123123
}
124124
}

src/runtime/eventobject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public static IntPtr tp_repr(IntPtr ob)
202202
{
203203
Runtime.XDecref(self.unbound.pyHandle);
204204
}
205-
FinalizeObject(self);
205+
self.Dealloc();
206206
}
207207
}
208208

src/runtime/extensiontype.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public static void FinalizeObject(ManagedType self)
5454
self.gcHandle.Free();
5555
}
5656

57+
protected void Dealloc()
58+
{
59+
FinalizeObject(this);
60+
FreeGCHandle();
61+
}
5762

5863
/// <summary>
5964
/// Type __setattr__ implementation.
@@ -88,8 +93,8 @@ public static void tp_dealloc(IntPtr ob)
8893
{
8994
// Clean up a Python instance of this extension type. This
9095
// frees the allocated Python object and decrefs the type.
91-
ManagedType self = GetManagedObject(ob);
92-
FinalizeObject(self);
96+
var self = (ExtensionType)GetManagedObject(ob);
97+
self.Dealloc();
9398
}
9499
}
95100
}

src/runtime/methodbinding.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public static IntPtr tp_repr(IntPtr ob)
244244
{
245245
var self = (MethodBinding)GetManagedObject(ob);
246246
self.ClearMembers();
247-
FinalizeObject(self);
247+
self.Dealloc();
248248
}
249249

250250
public static int tp_clear(IntPtr ob)

src/runtime/methodobject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public static IntPtr tp_repr(IntPtr ob)
208208
{
209209
var self = (MethodObject)GetManagedObject(ob);
210210
self.ClearMembers();
211-
ExtensionType.FinalizeObject(self);
211+
self.Dealloc();
212212
}
213213

214214
public static int tp_clear(IntPtr ob)

src/runtime/moduleobject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ public static IntPtr tp_repr(IntPtr ob)
305305
{
306306
var self = (ModuleObject)GetManagedObject(ob);
307307
tp_clear(ob);
308-
ExtensionType.tp_dealloc(ob);
308+
self.Dealloc();
309309
}
310310

311311
public static int tp_traverse(IntPtr ob, IntPtr visit, IntPtr arg)

src/runtime/overload.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static IntPtr tp_repr(IntPtr op)
6565
{
6666
var self = (OverloadMapper)GetManagedObject(ob);
6767
Runtime.XDecref(self.target);
68-
FinalizeObject(self);
68+
self.Dealloc();
6969
}
7070
}
7171
}

0 commit comments

Comments
 (0)