Skip to content

Commit

Permalink
Try deferred Garbage collection.
Browse files Browse the repository at this point in the history
  • Loading branch information
dombesz committed Jan 25, 2024
1 parent e65d529 commit b0101c5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,12 @@
# test failures related to randomization by passing the same `--seed` value
# as the one that triggered the failure.
Kernel.srand config.seed

config.before(:all) do
DeferredGarbageCollection.start
end

config.after(:all) do
DeferredGarbageCollection.reconsider
end
end
18 changes: 18 additions & 0 deletions spec/support/deferred_garbage_collection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class DeferredGarbageCollection
DEFERRED_GC_THRESHOLD = (ENV['DEFER_GC'] || 10.0).to_f

@@last_gc_run = Time.current

def self.start
GC.disable if DEFERRED_GC_THRESHOLD > 0
end

def self.reconsider
if DEFERRED_GC_THRESHOLD > 0 && Time.current - @@last_gc_run >= DEFERRED_GC_THRESHOLD
GC.enable
GC.start
GC.disable
@@last_gc_run = Time.current
end
end
end

0 comments on commit b0101c5

Please sign in to comment.