Project

General

Profile

Actions

Bug #9938

closed

ObjectSpace::allocation_class_path does not object's class

Added by dunric (David Unric) over 10 years ago. Updated over 10 years ago.

Status:
Rejected
Target version:
-
ruby -v:
2.1.2
[ruby-core:63141]

Description

Possible bug in ObjectSpace::allocation_class_path returning nil instead of expected class name:

require 'objspace'

class A
  def foo
    ObjectSpace::trace_object_allocations do
      obj = Object.new
      p ObjectSpace::allocation_class_path(obj)  # "A" expected, prints nil instead
      obj = Array.new
      p ObjectSpace::allocation_class_path(obj)  # "A" expected, prints nil instead
      obj = []
      p ObjectSpace::allocation_class_path(obj)  # prints "A" as expected !!
      obj = obj.dup
      p ObjectSpace::allocation_class_path(obj)  # "A" expected, prints nil instead !!
      obj = Hash.new
      p ObjectSpace::allocation_class_path(obj)  # "A" expected, prints nil instead
      obj = {}
      p ObjectSpace::allocation_class_path(obj)  # prints "A" as expected !!
    end
  end
end

A.new.foo

Very inconsistent behavior, allocation_class_path seems to works only with objects defined with literals not instantiated with class.new method.

Also discussed at StackOverflow:
http://stackoverflow.com/questions/24181789/objectspaceallocation-class-path-not-working-as-expected

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0