Re: Phix+EuGTK
- Posted by petelomax Jan 27, 2021
- 1847 views
When or how is it called?
The private destroy_instance() in builtins\structs.e is called when the reference count of an instance drops to zero, as per delete_routine(), or when delete(instance) is explicitly invoked.
Should a destructor be defined, it is invoked out of courtesy so the app can do any needed housekeeping.
Do I have to connect every widget's "destroy" signal to call the deconstructor for that class of widget?
I wouldn't think so, delete_routine() should take care of it, eventually - in some cases an explicit delete(instance) might fix some race condition.
Generally speaking all reference counts are tidied up when a routine returns, but an active loop might squirrel away a reference in a hidden temp (or explicit local var) until the next iteration.
Obviously, should you invoke delete(instance) but keep a reference, that is explicitly, and try to keep on using it, that's on you: sometimes it'll crash, sometimes it'll clobber a (new) sibling.
Here I'm just using it so that get_by_handle() does not return (long-)dead window handles, and in such simple code race conditions would seem quite unlikely.
What does it do besides remove the Window instance from the dictionary?
destroy_instance() places the slot in the (also private) instance table on a free list for re-use (ditto now-unused dicts from any dynamic class instances).
If it didn't do that some applications might exhibit a continuous memory leak.