Created
          December 13, 2012 16:46 
        
      - 
      
 - 
        
Save anonymous/4277829 to your computer and use it in GitHub Desktop.  
    Ruby Garbage Collector not garbage collecting as expected
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | class Person | |
| def self.destructor name | |
| proc{ puts "I AM DYING: #{name}"} | |
| end | |
| attr_reader :name | |
| def initialize name | |
| @name = name | |
| ObjectSpace.define_finalizer self, Person.destructor(name) | |
| end | |
| end | |
| p = Person.new 'John' | |
| p = nil | |
| GC.start | |
| # person 'John' is not garbage collected now, why? | |
| Person.new 'Thomas' | |
| GC.start | |
| # I AM DYING: John # Person 'John' is garbage collected | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
[*] unless of course there is a SegFault :)