<commit_before>require "java" if RUBY_ENGINE == "jruby"

#A simple weak-reference framework with mapping. Only handles the referencing of objects.
#===Examples
# user_obj = ob.get(:User, 1)
# weak_ref = Wref.new(user_obj)
# user_obj = nil
# sleep 0.5
# GC.start
#
# begin
#   user_obj = weak_ref.get
#   print "The user still exists in memory and has ID #{user.id}."
# rescue Wref::Recycled
#   print "The user has been removed from memory."
# end
class Wref
  #Returns the classname of the object.
  attr_reader :class_name
  
  #Returns the object-ID which is used to look up the ObjectSpace (if not running JRuby).
  attr_reader :id
  
  #Initializes various variables.
  def initialize(obj)
    if RUBY_ENGINE == "jruby"
      @weakref = java.lang.ref.WeakReference.new(obj)
    else
      @id = obj.__id__
      @class_name = obj.class.name.to_sym
      ObjectSpace.define_finalizer(obj, self.method(:destroy))
      
      if obj.respond_to?(:__object_unique_id__)
        @unique_id = obj.__object_unique_id__
      end
    end
  end
  
  #Destroyes most variables on the object, releasing memory and returning 'Wref::Recycled' all the time.
  def destroy<commit_msg>"destroy" takes arguments to work with destructors.<commit_after>require "java" if RUBY_ENGINE == "jruby"

#A simple weak-reference framework with mapping. Only handles the referencing of objects.
#===Examples
# user_obj = ob.get(:User, 1)
# weak_ref = Wref.new(user_obj)
# user_obj = nil
# sleep 0.5
# GC.start
#
# begin
#   user_obj = weak_ref.get
#   print "The user still exists in memory and has ID #{user.id}."
# rescue Wref::Recycled
#   print "The user has been removed from memory."
# end
class Wref
  #Returns the classname of the object.
  attr_reader :class_name
  
  #Returns the object-ID which is used to look up the ObjectSpace (if not running JRuby).
  attr_reader :id
  
  #Initializes various variables.
  def initialize(obj)
    if RUBY_ENGINE == "jruby"
      @weakref = java.lang.ref.WeakReference.new(obj)
    else
      @id = obj.__id__
      @class_name = obj.class.name.to_sym
      ObjectSpace.define_finalizer(obj, self.method(:destroy))
      
      if obj.respond_to?(:__object_unique_id__)
        @unique_id = obj.__object_unique_id__
      end
    end
  end
  
  #Destroyes most variables on the object, releasing memory and returning 'Wref::Recycled' all the time. It takes arguments because it can be called from destructor of the original object. It doesnt use the arguments for anything.
  def destroy(*args)
{'fraction_non_alphanumeric': 0.09210003969829297, 'fraction_numerical': 0.0023818975784041284, 'mean_word_length': 3.476021314387211, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3890515', 'n_tokens_mistral': 829, 'n_tokens_neox': 801, 'n_words': 266}