mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-01 15:03:39 +02:00
We call g_object_weak_release_all() at two places. Once right before finalize(). At this point, the object is definitely going to be destroyed, and the user must no longer resurrect it or subscribe new weak notifications. In that case, we really want to notify/release all weak notifications. However, we also call it from g_object_real_dispose(). During dispose, the API allows the user to resurrect an object. Granted, that is probably not something anybody should do, but GObject makes a reasonable attempt to support that. A possible place to resurrect (and subscribe new weak notifications) is when GObject calls g_object_real_dispose(). static void g_object_real_dispose (GObject *object) { g_signal_handlers_destroy (object); /* GWeakNotify and GClosure can call into user code */ g_object_weak_release_all (object); closure_array_destroy_all (object); } But previously, g_object_weak_release_all() would continue iterating until there are no more weak notifications left. So while the user can take a strong reference and resurrect the object, their attempts to register new weak notifications are thwarted. Instead, when the loop in g_object_weak_release_all() starts, remember the initial number of weak notifications, and don't release more than that. Note that WeakRefStack preserves the order of entries, so by maintaining the "remaining_to_notify" counter we know when to stop. Note that this brings also an earlier behavior back, where we would call g_datalist_id_set_data (&object->qdata, quark_weak_notifies, NULL); This would take out the entire WeakRefStack at once and notify the weak notifications registered at the time. But subsequent registrations would not be released/notified yet.