After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 709243 - Changing backgrounds leaks as much as 50MB of memory
Changing backgrounds leaks as much as 50MB of memory
Status: RESOLVED FIXED
Product: gnome-control-center
Classification: Core
Component: Background
3.10.x
Other Linux
: Normal major
: ---
Assigned To: Debarshi Ray
Control-Center Maintainers
: 685438 (view as bug list)
Depends on: 709264 709271
Blocks:
 
 
Reported: 2013-10-02 04:05 UTC by Kristof
Modified: 2015-10-27 12:37 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
background: Fix memory leak in the picture sources (2.31 KB, patch)
2013-10-02 14:35 UTC, Bastien Nocera
needs-work Details | Review
background: Fix leak of the preview picture (819 bytes, patch)
2013-10-02 14:35 UTC, Bastien Nocera
committed Details | Review
background: Fix leak of the Flickr source (1.08 KB, patch)
2013-10-02 14:35 UTC, Bastien Nocera
committed Details | Review
background: Add test program for the selection dialog (3.15 KB, patch)
2013-10-02 14:35 UTC, Bastien Nocera
committed Details | Review
background: Fix memory leak in Pictures source (887 bytes, patch)
2013-10-02 14:35 UTC, Bastien Nocera
committed Details | Review
background: Fix memory leak in background item object (1016 bytes, patch)
2013-10-02 14:35 UTC, Bastien Nocera
committed Details | Review
background: Fix memory leaks in slideshow handling (1.19 KB, patch)
2013-10-02 14:35 UTC, Bastien Nocera
committed Details | Review
background: Fix a memory leak when monitoring directories (1.04 KB, patch)
2013-10-02 14:35 UTC, Bastien Nocera
needs-work Details | Review
background: Fix memory leak in the picture sources (1.75 KB, patch)
2013-10-02 16:22 UTC, Bastien Nocera
committed Details | Review
background: Fix memory leak in XML signal handling (1.20 KB, patch)
2013-10-02 16:22 UTC, Bastien Nocera
needs-work Details | Review
background: Fix memory leak in XML signal handling (954 bytes, patch)
2013-10-02 16:53 UTC, Bastien Nocera
committed Details | Review
background: Fix a memory leak when monitoring directories (1.56 KB, patch)
2013-10-02 17:10 UTC, Bastien Nocera
accepted-commit_now Details | Review
background: Fix a memory leak when monitoring directories (1.56 KB, patch)
2013-10-02 17:31 UTC, Bastien Nocera
committed Details | Review

Description Kristof 2013-10-02 04:05:00 UTC
Using gnome-control-center to change backgrounds causes anywhere from 20MB to 50MB of RAM to be consumed by gnome-control-center.

Simply open up Settings, open up a system monitor in the background, keep an eye on gnome-control-center, and change the background several times (I used the backgrounds supplied by gnome). You should notice the RAM usage skyrocket.

Build date was Tue 24 Sep 2013 07:24:24 AM PDT, distributed by Arch Linux, v3.10.0-1
Comment 1 Bastien Nocera 2013-10-02 14:35:00 UTC
Created attachment 256273 [details] [review]
background: Fix memory leak in the picture sources

The list store was taking a reference to the background item,
so we need to unref it on our side to avoid leaking it.
Comment 2 Bastien Nocera 2013-10-02 14:35:05 UTC
Created attachment 256274 [details] [review]
background: Fix leak of the preview picture
Comment 3 Bastien Nocera 2013-10-02 14:35:10 UTC
Created attachment 256275 [details] [review]
background: Fix leak of the Flickr source

The Flickr source was never disposed of when destroying the
selection dialog.
Comment 4 Bastien Nocera 2013-10-02 14:35:15 UTC
Created attachment 256276 [details] [review]
background: Add test program for the selection dialog
Comment 5 Bastien Nocera 2013-10-02 14:35:20 UTC
Created attachment 256277 [details] [review]
background: Fix memory leak in Pictures source

The enumerator was never unref'ed.
Comment 6 Bastien Nocera 2013-10-02 14:35:25 UTC
Created attachment 256278 [details] [review]
background: Fix memory leak in background item object

Some fields were never freed.
Comment 7 Bastien Nocera 2013-10-02 14:35:30 UTC
Created attachment 256279 [details] [review]
background: Fix memory leaks in slideshow handling

A string was leaked when loading the name of the slideshow,
and a file object was left lingering as well.
Comment 8 Bastien Nocera 2013-10-02 14:35:35 UTC
Created attachment 256280 [details] [review]
background: Fix a memory leak when monitoring directories

Destroy directory monitors on when the XML object is destroyed.
Comment 9 Debarshi Ray 2013-10-02 15:54:59 UTC
Review of attachment 256273 [details] [review]:

::: panels/background/bg-wallpapers-source.c
@@ +119,3 @@
 
+  g_clear_object (&pixbuf);
+  g_object_unref (item);

I think we shouldn't be releasing the reference to the item in the BgWallpapersSource. Instead CcBackgroundXml should be managing the lifetime of item when it emits the "added" signal. eg., idle_emit in CcBackgroundXml already unrefs the item after emitting the signal.

Looking at cc_background_xml_load_xml_internal (the other place where the signal is emitted) I think the item should be unrefed once the signal has been emitted.
Comment 10 Debarshi Ray 2013-10-02 15:57:54 UTC
Review of attachment 256274 [details] [review]:

Looks good to me.
Comment 11 Thomas Wood 2013-10-02 15:58:11 UTC
Review of attachment 256273 [details] [review]:

Looks good to me.
Comment 12 Debarshi Ray 2013-10-02 15:59:45 UTC
Review of attachment 256275 [details] [review]:

Looks good to me.
Comment 13 Debarshi Ray 2013-10-02 16:00:33 UTC
Comment on attachment 256273 [details] [review]
background: Fix memory leak in the picture sources

Put it back to needs-work, because I am really not sure about it.
Comment 14 Debarshi Ray 2013-10-02 16:12:48 UTC
Review of attachment 256276 [details] [review]:

::: panels/background/Makefile.am
@@ +22,3 @@
 	gdesktop-enums-types.h
 
+noinst_LTLIBRARIES = libbackground.la libbackground-chooser.la

Why did you move the noinst_LTLIBRARIES? If you kept it where it was, the patch would be easier to read.

::: panels/background/test-chooser-dialog.c
@@ +12,3 @@
+}
+
+int main (int argc, char **argv)

Return type should be on a separate line.
Comment 15 Debarshi Ray 2013-10-02 16:13:52 UTC
Review of attachment 256277 [details] [review]:

Looks good to me.
Comment 16 Debarshi Ray 2013-10-02 16:19:48 UTC
Review of attachment 256278 [details] [review]:

Looks good to me.
Comment 17 Bastien Nocera 2013-10-02 16:22:40 UTC
Created attachment 256292 [details] [review]
background: Fix memory leak in the picture sources

The list store was taking a reference to the background item,
so we need to unref it on our side to avoid leaking it.
Comment 18 Bastien Nocera 2013-10-02 16:22:55 UTC
Created attachment 256293 [details] [review]
background: Fix memory leak in XML signal handling

When emitted in an idle, the item was correctly unref'ed, but not
when emitting the signal straight away.
Comment 19 Debarshi Ray 2013-10-02 16:34:20 UTC
Review of attachment 256279 [details] [review]:

Looks good to me.
Comment 20 Debarshi Ray 2013-10-02 16:49:53 UTC
Review of attachment 256280 [details] [review]:

::: panels/background/cc-background-xml.c
@@ +370,3 @@
+  g_signal_connect_object (monitor, "changed",
+                           G_CALLBACK (gnome_wp_file_changed),
+                           data, G_CONNECT_SWAPPED);

1) Using G_CONNECT_SWAPPED is wrong because it does not match with the signature of gnome_wp_file_changed.
2) The monitor is still leaked.
Comment 21 Debarshi Ray 2013-10-02 16:52:22 UTC
Review of attachment 256292 [details] [review]:

Looks good to me.
Comment 22 Bastien Nocera 2013-10-02 16:53:49 UTC
Created attachment 256297 [details] [review]
background: Fix memory leak in XML signal handling

When emitted in an idle, the item was correctly unref'ed, but not
when emitting the signal straight away.
Comment 23 Debarshi Ray 2013-10-02 16:57:50 UTC
Review of attachment 256293 [details] [review]:

::: panels/background/cc-background-xml.c
@@ +318,2 @@
         g_signal_emit (G_OBJECT (xml), signals[ADDED], 0, item);
+        g_object_unref (item);

It should be unreffed in both cases.
Comment 24 Debarshi Ray 2013-10-02 16:58:20 UTC
Review of attachment 256297 [details] [review]:

Looks good to me.
Comment 25 Bastien Nocera 2013-10-02 17:02:50 UTC
FWIW, the major leak was a GTK+ bug, see the blocker bugs. It was leaking the original image for each of the backgrounds.
Comment 26 Bastien Nocera 2013-10-02 17:05:41 UTC
Pushed all those to gnome-3-8 and master.

Attachment 256274 [details] pushed as fc4be32 - background: Fix leak of the preview picture
Attachment 256275 [details] pushed as 42f2f43 - background: Fix leak of the Flickr source
Attachment 256276 [details] pushed as fba69ce - background: Add test program for the selection dialog
Attachment 256277 [details] pushed as c9c28e0 - background: Fix memory leak in Pictures source
Attachment 256278 [details] pushed as 4102ad2 - background: Fix memory leak in background item object
Attachment 256279 [details] pushed as 756b9e7 - background: Fix memory leaks in slideshow handling
Attachment 256292 [details] pushed as 6094ea6 - background: Fix memory leak in the picture sources
Attachment 256297 [details] pushed as 86e61a4 - background: Fix memory leak in XML signal handling
Comment 27 Bastien Nocera 2013-10-02 17:10:30 UTC
Created attachment 256303 [details] [review]
background: Fix a memory leak when monitoring directories

Destroy directory monitors on when the XML object is destroyed.
Comment 28 Debarshi Ray 2013-10-02 17:16:44 UTC
(In reply to comment #14)
> Review of attachment 256276 [details] [review]:
> 
> ::: panels/background/Makefile.am
> @@ +22,3 @@
>      gdesktop-enums-types.h
> 
> +noinst_LTLIBRARIES = libbackground.la libbackground-chooser.la
> 
> Why did you move the noinst_LTLIBRARIES? If you kept it where it was, the patch
> would be easier to read.
> 
> ::: panels/background/test-chooser-dialog.c
> @@ +12,3 @@
> +}
> +
> +int main (int argc, char **argv)
> 
> Return type should be on a separate line.

I was expecting you to clean this up before pushing. :-(
Comment 29 Debarshi Ray 2013-10-02 17:20:22 UTC
Review of attachment 256303 [details] [review]:

Looks good to me.
Comment 30 Bastien Nocera 2013-10-02 17:31:22 UTC
Created attachment 256304 [details] [review]
background: Fix a memory leak when monitoring directories

Destroy directory monitors on when the XML object is destroyed.
Comment 31 Bastien Nocera 2013-10-02 17:34:13 UTC
Attachment 256304 [details] pushed as 732f864 - background: Fix a memory leak when monitoring directories
Comment 32 Debarshi Ray 2015-10-27 12:37:46 UTC
*** Bug 685438 has been marked as a duplicate of this bug. ***