Method: Contrast::Agent::Assess::Finalizers::Hash#finalizing_proc

Defined in:
lib/contrast/agent/assess/finalizers/hash.rb

#finalizing_procProc

Create a Proc to remove the given key from our frozen and properties tracking during finalization of the Object to which the given key_id pertains. The ObjectSpace’s finalizer mechanism will handle passing this ID in, so we only need to define the Proc once.

NOTE: by necessity, this is the only method which takes the __id__, not the Object itself. You CANNOT pass the Object to this as a finalizer cannot hold reference to the Object being finalized; that prevents GC, which introduces a memory leak and defeats the entire purpose of this.

Returns:

  • (Proc)

    the Proc to remove references to the ID of the GC’d object from our Hash



78
79
80
81
82
83
84
# File 'lib/contrast/agent/assess/finalizers/hash.rb', line 78

def finalizing_proc
  @_finalizing_proc ||= proc do |key_id|
    FROZEN_FINALIZED_IDS.delete(key_id)
    Contrast::Agent::Assess::Policy::PropagationMethod.instance_variable_get(:@properties).delete(key_id)
    delete(key_id)
  end
end