-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix class-freed-before-instance-bug.
In some rare instances, class objects can be freed before the last instance of that class, causing a problem in the sweep phase where we look at the class of the object being freed. So we keep unreachable classes around for an extra collection to be safe.
- Loading branch information
Showing
5 changed files
with
69 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import gc | ||
|
||
# Dynamically create new classes and instances of those classes in such a way | ||
# that both the class object and the instance object will be freed in the same | ||
# garbage collection pass. Hope that this doesn't cause any problems. | ||
def generateClassAndInstances(): | ||
for i in xrange(5000): | ||
def method(self, x): | ||
return x + self.i | ||
NewType1 = type("Class1_" + str(i), (), | ||
dict(a={}, b=range(10), i=1, f=method)) | ||
NewType2 = type("Class2_" + str(i), (object,), | ||
dict(a={}, b=range(10), i=2, f=method)) | ||
NewType3 = type("Class3_" + str(i), (NewType2,), {}) | ||
NewType4 = type("Class4_" + str(i), (NewType3,), {}) | ||
NewType5 = type("Class5_" + str(i), (NewType4,), {}) | ||
obj1 = NewType1() | ||
obj2 = NewType2() | ||
obj3 = NewType3() | ||
obj4 = NewType4() | ||
obj5 = NewType5() | ||
|
||
generateClassAndInstances() | ||
gc.collect() | ||
gc.collect() |