From: Clemens Hintze Date: 1999-01-15T10:51:06+00:00 Subject: [ruby-talk:00186] Re: finalizer help please Hmm. Here seems to exit two problems. First Ruby assume that DestroyWindow is a method. Is it possible that the contents of WINGKRUser are encapsulated via module ... end? If so you should call the function like that ::DestrowWindow(@handle) or .DestroyWindow(@handle). Alternativ you could also perform a include after the require. The second should be, that your destructor should never be called, I think. I have done a very similar approach for my first module. Matz has told me then, that my destructor helds a pointer to self, means to my instance I wish to finalize! Due to that fact the GC will never recognize my instance as unused. So no finalization should take place, as there is a pointer to my instance all the time. And for GC pointer-to-instance means "used". Furthermore I wonder, why you deliver self to the WinControl.destructor call. You assume, that you points to the current instance as you use @handle. But you have also delivered the current instance to the obj variable. That is, you should now have too much two pointers to the current instance. If no other variable within he Ruby interpreter points to that instance, at least self and obj will point to it. No chance for GC! So if my explanation was true and I remember right, you could rewrite your destructor as follow: def WinControl.destructor ( handle ) lambda { require 'WINGKRUser32' if handle != 0 then if ::DestroyWindow ( handle ) != 0 then print "\n\r Destroyed: ", handle else print "\n\r Could NOT destroy: ", handle end end } end Here, no pointer to self should be held. So the GC can detect that your instance is unused. I hope the explanaitions was correct. Ciao, Cle.