Reference monitoring on GObject

110 views Asked by At

What I found is:

https://docs.gtk.org/gobject/method.Object.add_toggle_ref.html

I have this problem:

When signal handler for some GtkWidget is called, I cannot delete this widget. One solution is to create timer and delete it in timer procedure, but what If I call additional messages loop inside event handler routine? I do not known if (in this case) signal for widget are blocked, but maybe I need to destroy parent widget in event handler for child?

One solution is to increase reference count, when entering event handler and decrease it, before quit signal handler for widget. But from what I will known to create timer? I guess, I may save if widget should be destroyed (in property, for example) and check if reference count is (for example): 1. If reference count is equal some value and widget contain information, it should been destroyed, then I create timer with procedure to destroy widget (decreasing reference by 1). In this case, reference count only be 1 at end of first event handler of widget. When we reach end of signal handler and test that widget should been destroyed, we create timer, so we are 100% sure, that widget will be destroyed outside one's event handler.

Problem is: I got segfault, because I destroy window or widget inside one's event handler. When callback reach bottom and execution flow exit, Gtk+ does something strange with widget.

Only one think is still missing: I cannot read reference count of given GObject.

0

There are 0 answers