class Autogc

This class disables garbage collection

Public Class Methods

enable_for_known_buggy_env(args = {}) click to toggle source

Starts autogc if it is running on a known buggy environment.

# File lib/autogc.rb, line 14
def self.enable_for_known_buggy_env(args = {})
  found = false
  found = true if RUBY_VERSION == "1.9.3"
  Autogc.new(args) if found
  return found
end
new(args = {}) click to toggle source

Disables the normal GC and enables a timeout to automatically GC.

# File lib/autogc.rb, line 4
def initialize(args = {})
  @args = args
  
  puts "Starting Autogc." if @args[:debug]
  @args[:time] = 1
  @thread = Thread.new(&self.method(:gc_loop))
  GC.disable
end

Public Instance Methods

gc() click to toggle source

Execute garbage-collection exclusive.

# File lib/autogc.rb, line 40
def gc
  Thread.exclusive do
    puts "Autogc: Doing garbage collection." if @args[:debug]
    GC.enable
    GC.start
    GC.disable
  end
end
gc_loop() click to toggle source

Starts the loop that executes the garbage-collection.

# File lib/autogc.rb, line 28
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() click to toggle source

Stops the garbage-collection on time and enables the normal GC.

# File lib/autogc.rb, line 22
def stop
  GC.enable
  @thread.kill
end