Class: Autogc
- Inherits:
-
Object
- Object
- Autogc
- Defined in:
- lib/autogc.rb
Overview
This class disables garbage collection
Instance Method Summary collapse
-
#gc ⇒ Object
Execute garbage-collection exclusive.
-
#gc_loop ⇒ Object
Starts the loop that executes the garbage-collection.
-
#initialize(args = {}) ⇒ Autogc
constructor
Disables the normal GC and enables a timeout to automatically GC.
-
#stop ⇒ Object
Stops the garbage-collection on time and enables the normal GC.
Constructor Details
#initialize(args = {}) ⇒ Autogc
Disables the normal GC and enables a timeout to automatically GC.
4 5 6 7 8 9 |
# File 'lib/autogc.rb', line 4 def initialize(args = {}) @args = args @args[:time] = 1 @thread = Thread.new(&self.method(:gc_loop)) GC.disable end |
Instance Method Details
#gc ⇒ Object
Execute garbage-collection exclusive.
30 31 32 33 34 35 36 37 |
# File 'lib/autogc.rb', line 30 def gc Thread.exclusive do puts "Autogc: Doing garbage collection." if @args[:debug] GC.enable GC.start GC.disable end end |
#gc_loop ⇒ Object
Starts the loop that executes the garbage-collection.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/autogc.rb', line 18 def gc_loop loop do begin sleep @args[:time] self.gc rescue => e puts "Autogc: An error occurred while triggering the garbage-collection." end end end |
#stop ⇒ Object
Stops the garbage-collection on time and enables the normal GC.
12 13 14 15 |
# File 'lib/autogc.rb', line 12 def stop GC.enable @thread.kill end |