# File bin/el4r-instance, line 204
    def garbage_collect
      pre_gc_hook
      stock_ids = @oid_to_obj_hash.keys
      stock_ids.sort!
      @instance.el4r_debug { "(GC) 1" }
      alive_ids = @instance.el4r_rubyobj_get_alive_ids.to_a # funcall
      @instance.el4r_debug { "(GC) 2" }
      alive_ids.collect! { |id| id.to_i; }
      alive_ids.sort!

      @instance.el4r_debug { "(GC) Stocked IDs: #{stock_ids.inspect}"; }
      @instance.el4r_debug { "(GC) Alive IDs: #{alive_ids.inspect}"; }

      freed_ids = []
      while aid = alive_ids.pop
        while true
          sid = stock_ids.pop or raise(El4rError, "Can't happen!")
          break if sid == aid
          freed_ids << sid
        end
      end
      freed_ids.concat(stock_ids)

      @instance.el4r_debug { "(GC) IDs to free: #{freed_ids.inspect}"; }
      freed_ids.each { |id|
        @oid_to_obj_hash.delete(id)
      }

      @instance.el4r_debug { "(GC) Count of stocked object is reduced to #{count_of_stocked_objects}"; }
      post_gc_hook
    end