[tepl] AmtkFactory: weak ref to the GtkApplication
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tepl] AmtkFactory: weak ref to the GtkApplication
- Date: Mon, 31 Jul 2017 09:21:50 +0000 (UTC)
commit dbd04bf21b4a7351bbe4e3da1678aa9fc1bf3d5c
Author: Sébastien Wilmet <swilmet gnome org>
Date: Mon Jul 31 11:11:53 2017 +0200
AmtkFactory: weak ref to the GtkApplication
amtk/amtk-factory.c | 25 ++++++++++++++++---------
1 files changed, 16 insertions(+), 9 deletions(-)
---
diff --git a/amtk/amtk-factory.c b/amtk/amtk-factory.c
index 709ad3a..437fecb 100644
--- a/amtk/amtk-factory.c
+++ b/amtk/amtk-factory.c
@@ -45,15 +45,13 @@
* #AmtkFactory:default-flags. See for example
* amtk_factory_menu_create_menu_item() and
* amtk_factory_menu_create_menu_item_full().
- *
- * Once the objects are created, an #AmtkFactory should be freed because it has
- * a strong reference to the #GtkApplication. TODO: change it to a weak ref
- * instead so that this paragraph can be removed.
*/
struct _AmtkFactoryPrivate
{
+ /* Weak ref */
GtkApplication *app;
+
AmtkFactoryFlags default_flags;
};
@@ -105,7 +103,12 @@ amtk_factory_set_property (GObject *object,
{
case PROP_APPLICATION:
g_assert (factory->priv->app == NULL);
- factory->priv->app = g_value_dup_object (value);
+ factory->priv->app = g_value_get_object (value);
+ if (factory->priv->app != NULL)
+ {
+ g_object_add_weak_pointer (G_OBJECT (factory->priv->app),
+ (gpointer *) &factory->priv->app);
+ }
break;
case PROP_DEFAULT_FLAGS:
@@ -123,7 +126,12 @@ amtk_factory_dispose (GObject *object)
{
AmtkFactory *factory = AMTK_FACTORY (object);
- g_clear_object (&factory->priv->app);
+ if (factory->priv->app != NULL)
+ {
+ g_object_remove_weak_pointer (G_OBJECT (factory->priv->app),
+ (gpointer *) &factory->priv->app);
+ factory->priv->app = NULL;
+ }
G_OBJECT_CLASS (amtk_factory_parent_class)->dispose (object);
}
@@ -140,9 +148,8 @@ amtk_factory_class_init (AmtkFactoryClass *klass)
/**
* AmtkFactory:application:
*
- * The associated #GtkApplication. #AmtkFactory has a strong reference
- * to the #GtkApplication (which means that once the widgets are created
- * you should free the #AmtkFactory).
+ * The associated #GtkApplication (it is optional, it can be %NULL).
+ * #AmtkFactory has a weak reference to the #GtkApplication.
*
* Since: 3.0
*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]