Class: Rspectacular::DeferredGarbageCollection
- Inherits:
-
Object
- Object
- Rspectacular::DeferredGarbageCollection
- Defined in:
- lib/rspectacular/support/garbage_collection.rb
Constant Summary collapse
- THRESHOLD =
(ENV['DEFER_GC'] || 20.0).to_f
Class Attribute Summary collapse
Class Method Summary collapse
- .cycle_garbage_collector ⇒ Object
- .enabled? ⇒ Boolean
- .over_deferrment_threshold? ⇒ Boolean
- .reconsider ⇒ Object
- .start ⇒ Object
- .time_since_garbage_last_collected ⇒ Object
Class Attribute Details
.garbage_last_collected_at ⇒ Object
41 42 43 |
# File 'lib/rspectacular/support/garbage_collection.rb', line 41 def self.garbage_last_collected_at @garbage_last_collected_at || Time.now end |
Class Method Details
.cycle_garbage_collector ⇒ Object
23 24 25 26 27 |
# File 'lib/rspectacular/support/garbage_collection.rb', line 23 def self.cycle_garbage_collector GC.enable GC.start GC.disable end |
.enabled? ⇒ Boolean
33 34 35 |
# File 'lib/rspectacular/support/garbage_collection.rb', line 33 def self.enabled? THRESHOLD > 0 end |
.over_deferrment_threshold? ⇒ Boolean
29 30 31 |
# File 'lib/rspectacular/support/garbage_collection.rb', line 29 def self.over_deferrment_threshold? time_since_garbage_last_collected >= THRESHOLD end |
.reconsider ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/rspectacular/support/garbage_collection.rb', line 15 def self.reconsider if enabled? && over_deferrment_threshold? cycle_garbage_collector self.garbage_last_collected_at = Time.now end end |
.start ⇒ Object
11 12 13 |
# File 'lib/rspectacular/support/garbage_collection.rb', line 11 def self.start cycle_garbage_collector if enabled? end |
.time_since_garbage_last_collected ⇒ Object
37 38 39 |
# File 'lib/rspectacular/support/garbage_collection.rb', line 37 def self.time_since_garbage_last_collected Time.now - garbage_last_collected_at end |