From: Lyle Johnson Date: 2004-05-19T08:43:49+09:00 Subject: Re: FoX: removing widgets Yuri Leikind wrote: > When I need to delete some widget, I do it like this: > > parent_obj.removeChild(obj_to_remove) > > and then create and recalc > > But, though the object deleted does not belong anywhere in the hierarchy of GUI objects, > it still exists. Correct. Calling removeChild() deletes the underlying C++ object. The Ruby object that was referring to that C++ object is no longer in use, but it hasn't been garbage-collected yet. > I have a ObjectSpace.each_object() loop in my program iterating over some > of FXObjects, setting new font and text. Naturally, doing anything to a removed object > causes error "This FXLabel (or FXWindow, or ...) * already released". Yes. Accessing a Ruby object whose C++ partner is gone is a no-no. > So, I have two questions: > > 1) Is there a way to find out whether the object has already been released? I don't guess so (it has never come up). If you were to add this request to the list of FXRuby bugs at SourceForge, I might add a way to find out this information in a future FXRuby release. > 2) What else must be done to the FoX object that we want to delete, besides > parent_obj.removeChild(obj_to_remove) I guess you can try forcing the garbage collector to run immediately after the call to removeChild(), i.e. parent.removeChild(child) GC.start Hope this helps, Lyle