Skip to content

Instantly share code, notes, and snippets.

@Hamdiakoguz
Hamdiakoguz / gogo.rb
Created October 4, 2015 21:06 — forked from mboeh/gogo.rb
thread and GC nuance
# Summary: In MRI 1.9, if you keep threads in an array in a local variable, the threads may outlive the local variable.
# I have not yet been able to produce a scenario in which the threads are ever garbage-collected.
# You have to remove the thread from the array before it goes out of scope, e.g. using #pop or #clear.
# INPUT DESIRED: If anyone can demonstrate a condition in which a local array keeps threads and those threads are eventually GC'd.
# INPUT DESIRED: Is this expected behavior or a bug?
# NOTE: This test will not work as expected in JRuby, because its garbage collection works differently. Whether the same behavior exists in JRuby is an exercise for someone smarter than I am.
class Foo
THREAD_PROC = lambda{ (0..10).to_a.map do Foo.new end }
var countries = {
'af' : 'Afganistan',
'de' : 'Almanya',
'ad' : 'Andorra',
'ao' : 'Angola',
'ag' : 'Antigua ve Barbuda',
'ar' : 'Arjantin',
'al' : 'Arnavutluk',
'aw' : 'Aruba',
'au' : 'Avustralya',