Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/core/IronPython.Modules/gc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@ public static object isenabled() {
return ScriptingRuntimeHelpers.True;
}

public static int collect(CodeContext context, int generation) {
return context.LanguageContext.Collect(generation);
}
public static void collect(CodeContext context, int generation)
=> context.LanguageContext.Collect(generation);

public static int collect(CodeContext context) {
return collect(context, GC.MaxGeneration);
}
public static void collect(CodeContext context)
=> collect(context, GC.MaxGeneration);

public static void set_debug(object? o) {
throw PythonOps.NotImplementedError("gc.set_debug isn't implemented");
Expand Down
8 changes: 1 addition & 7 deletions src/core/IronPython/Runtime/PythonContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3232,15 +3232,11 @@ public override IList<string> GetCallSignatures(object obj) {
/// Performs a GC collection including the possibility of freeing weak data structures held onto by the Python runtime.
/// </summary>
/// <param name="generation"></param>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods", MessageId = "System.GC.Collect")]
internal int Collect(int generation) {
internal void Collect(int generation) {
if (generation > GC.MaxGeneration || generation < 0) {
throw PythonOps.ValueError("invalid generation {0}", generation);
}

// now let the CLR do it's normal collection
long start = GC.GetTotalMemory(false);

for (int i = 0; i < 2; i++) {
GC.Collect(generation);
GC.WaitForPendingFinalizers();
Expand All @@ -3251,8 +3247,6 @@ internal int Collect(int generation) {
FunctionCode.CleanFunctionCodes(this, true);
}
}

return (int)Math.Max(start - GC.GetTotalMemory(false), 0);
}

public DynamicDelegateCreator DelegateCreator {
Expand Down
2 changes: 1 addition & 1 deletion tests/suite/modules/system_related/test_gc.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def test_isenabled(self):

def test_collect(self):
if is_cli:
i = gc.collect() # returns # of bytes collected, could be anything
self.assertIsNone(gc.collect()) # returns None, we don't track collected objects
else:
for debug in debug_list:
gc.set_debug(debug)
Expand Down
Loading