require 'phi'
include  Phi
form = Form.new
button1 = Button.new(form, :button1, "i am first button")
button1.align = AL_TOP

button1.on_click = proc{
  ObjectSpace.each_object(Button) do |button|
    puts button.caption	
  end
}

button2 = Button.new(form, :button2, "kill first button")
button2.align = AL_BOTTOM

button2.on_click = proc do |sender|
  unless button1.nil?
    p button1.parent
    button1.parent = nil		
#    button1.parent.instance_eval{@button1=nil}
    p button1.parent
    button1 = nil			
    p form.button1
  end
  GC.start				
    p form.button1
  ObjectSpace.each_object(Button) do |button|
    puts button.caption			
  end
end

form.show
Phi.mainloop
