Method: Object#memory_profile_size_of_object

Defined in:
lib/pmsrb/memory_profile.rb

#memory_profile_size_of_object(seen = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/pmsrb/memory_profile.rb', line 6

def memory_profile_size_of_object(seen={})
  return 0 if seen.has_key? object_id
  seen[object_id] = true
  count = 1
  if kind_of? Hash
    each_pair do |key,value|
      count += key.memory_profile_size_of_object(seen)
      count += value.memory_profile_size_of_object(seen)
    end
  elsif kind_of? Array
    count += size
    each do |element|
      count += element.memory_profile_size_of_object(seen)
    end
  end

  count += instance_variables.size
  instance_variables.each do |var|
    count += instance_variable_get(var.to_sym).memory_profile_size_of_object(seen)
  end

  count
end