Merge lp:~agateau/unity-2d/dash-fork-on-close into lp:unity-2d/3.0

Proposed by Aurélien Gâteau
Status: Rejected
Rejected by: Florian Boucault
Proposed branch: lp:~agateau/unity-2d/dash-fork-on-close
Merge into: lp:unity-2d/3.0
Diff against target: 66 lines (+34/-2)
2 files modified
places/app/dashdeclarativeview.cpp (+2/-1)
places/app/places.cpp (+32/-1)
To merge this branch: bzr merge lp:~agateau/unity-2d/dash-fork-on-close
Reviewer Review Type Date Requested Status
Florian Boucault (community) Disapprove
Review via email: mp+56792@code.launchpad.net

Description of the change

After running out of ideas to plug dash memory leaks, I came to try a workaround which can be summarized like this:

forever:
   run the dash in a subprocess
   when the user closes the view, exit the subprocess

It is definitely not a proper fix but it works well here. I believe the cost is acceptable: ld shouldn't load the libraries again so forking should remain fast, but it would need to be tested on lower-end machines.

To post a comment you must log in.
519. By Aurélien Gâteau

Do not fork endlessly when X goes down

Revision history for this message
Florian Boucault (fboucault) wrote :

Fix was committed to Qt4. This workaround is not needed anymore.

review: Disapprove

Unmerged revisions

519. By Aurélien Gâteau

Do not fork endlessly when X goes down

518. By Aurélien Gâteau

[dash] Work around memory leaks by running the application in a subprocess

See comments in places.cpp

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'places/app/dashdeclarativeview.cpp'
--- places/app/dashdeclarativeview.cpp 2011-03-23 11:30:21 +0000
+++ places/app/dashdeclarativeview.cpp 2011-04-07 21:46:49 +0000
@@ -147,9 +147,10 @@
147 DashDeclarativeView::DashMode oldMode = m_mode;147 DashDeclarativeView::DashMode oldMode = m_mode;
148 m_mode = mode;148 m_mode = mode;
149 if (m_mode == HiddenMode) {149 if (m_mode == HiddenMode) {
150 hide();
151 m_launcherClient->endForceVisible();150 m_launcherClient->endForceVisible();
152 activeChanged(false);151 activeChanged(false);
152 // See main() for why we do this instead of calling hide();
153 QApplication::exit(12);
153 } else {154 } else {
154 show();155 show();
155 raise();156 raise();
156157
=== modified file 'places/app/places.cpp'
--- places/app/places.cpp 2011-03-16 16:51:20 +0000
+++ places/app/places.cpp 2011-04-07 21:46:49 +0000
@@ -37,10 +37,23 @@
37#include <unity2ddebug.h>37#include <unity2ddebug.h>
38#include <unity2dtr.h>38#include <unity2dtr.h>
3939
40// libc
41#include <sys/wait.h>
42#include <stdio.h>
43
40#include "dashdeclarativeview.h"44#include "dashdeclarativeview.h"
41#include "config.h"45#include "config.h"
4246
43int main(int argc, char *argv[])47/*
48 * unity-2d-places has memory leaks which seem to come from within Qt
49 * Declarative itself. We workaround this by forking in main() and running the
50 * whole application in a child process which stops itself after the dash
51 * closes (see DashDeclarativeView::setDashMode()). When the child process stops,
52 * the main process creates a new one. This way memory is released but we save
53 * time on startup compared to the other solution of restarting the whole
54 * application because libraries have already been loaded.
55 */
56int childMain(int argc, char *argv[])
44{57{
45 /* gtk needs to be inited, otherwise we get an assert failure in gdk */58 /* gtk needs to be inited, otherwise we get an assert failure in gdk */
46 gtk_init(&argc, &argv);59 gtk_init(&argc, &argv);
@@ -90,3 +103,21 @@
90 application.setProperty("view", QVariant::fromValue(&view));103 application.setProperty("view", QVariant::fromValue(&view));
91 return application.exec();104 return application.exec();
92}105}
106
107int main(int argc, char* argv[])
108{
109 bool restart = true;
110 while (restart) {
111 pid_t pid = fork();
112 if (pid == 0) {
113 return childMain(argc, argv);
114 } else {
115 int status;
116 waitpid(pid, &status, 0);
117 fprintf(stderr, "Child exited with status %d\n", status);
118 // If exit code is not the "restart" exit code, quit: we do not
119 // want to prevent the session from ending
120 restart = WEXITSTATUS(status) == 12;
121 }
122 }
123}

Subscribers

People subscribed via source and target branches