Class: QuartzTorrent::MemProfiler

Inherits:
Object
  • Object
show all
Defined in:
lib/quartz_torrent/memprofiler.rb

Overview

Utility class used for debugging memory leaks. It can be used to count the number of reachable instances of selected classes.

Instance Method Summary collapse

Constructor Details

#initializeMemProfiler

Returns a new instance of MemProfiler.



6
7
8
# File 'lib/quartz_torrent/memprofiler.rb', line 6

def initialize
  @classes = []
end

Instance Method Details

#getCountsObject

Return a hashtable keyed by class where the value is the number of that class of object still reachable.



16
17
18
19
20
21
22
23
24
# File 'lib/quartz_torrent/memprofiler.rb', line 16

def getCounts
  result = {}
  @classes.each do |c|
    count = 0
    ObjectSpace.each_object(c){ count += 1 }
    result[c] = count
  end
  result
end

#trackClass(clazz) ⇒ Object

Add a class to the list of classes we count the reachable instances of.



11
12
13
# File 'lib/quartz_torrent/memprofiler.rb', line 11

def trackClass(clazz)
  @classes.push clazz
end