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 Method Summary collapse
- .cycle_garbage_collector ⇒ Object
- .enabled? ⇒ Boolean
- .garbage_last_collected_at ⇒ Object
- .garbage_last_collected_at=(value) ⇒ Object
- .over_deferrment_threshold? ⇒ Boolean
- .reconsider ⇒ Object
- .start ⇒ Object
- .time_since_garbage_last_collected ⇒ Object
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 |
.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 |
.garbage_last_collected_at=(value) ⇒ Object
45 46 47 |
# File 'lib/rspectacular/support/garbage_collection.rb', line 45 def self.garbage_last_collected_at=(value) @garbage_last_collected_at = value 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
13 14 15 16 17 18 19 |
# File 'lib/rspectacular/support/garbage_collection.rb', line 13 def self.reconsider if enabled? && over_deferrment_threshold? cycle_garbage_collector garbage_last_collected_at = Time.now end end |
.start ⇒ Object
9 10 11 |
# File 'lib/rspectacular/support/garbage_collection.rb', line 9 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 |