Il 30/09/2011 12:15, Jean-Marc Lasgouttes ha scritto:
What do we see?

1/ there is a continuous drift of memory use
2/ the most important part is the agregation of small allocations (not very useful...)
3/ the second one is related to font loading by qt (remains stable)
4/ the third one is the allocation of docstrings, stable too.

From 69 to 70, the increase is ~150k, and most of it is in the first agregated chunk. To understand what happens, you need to lower the 1% threshold (both when calling massif and ms_print) to maybe 0.5%, or at least until we see what is the particular stack trace which importance grows.

Does this help?

sure, thx for the explanations. I'll do that later.

Also, I tried to check the malloc() stack traces tagged as "definitely lost" by --tool=memcheck, and I came to the attached patch. It addresses some class instances which were not children of QObject, for which the destruction was not called, apparently (for QWidget and derivates, we seem to rely on Qt in freeing up things in the proper order).

It reduces the definitely lost chunks as follows (performed actions: launch LyX, C-n, C-w, Alt+F4 -- nothing else):

$ grep "   definitely lost" valgrind-log[19].txt
valgrind-log1.txt:==3849==    definitely lost: 12,126 bytes in 73 blocks
valgrind-log9.txt:==7203==    definitely lost: 5,678 bytes in 17 blocks

These are just cleanup ops that are not explicitly done on program exit, but not a big deal, actually. They could help in having a better cleanup of LyX at exit, but I'm not sure any of these deserves to be committed (pls, comment).

For the increased memory usage notified by Rudi, if there were any problem with handling the Undo instances, then we should have seen something about Undo into the valgrind log. If that doesn't happen, then I have no clue. The lyxfind.cpp code contains no explicit new operations. The only notable action is the creation of a temporary Buffer instance on the stack, which is (supposed to be) freed up automatically. Also, the Search and Replace Buffers (and WorkAreas) in the FindAdvanced dialog are never freed, along with their Undo lists, etc.... However, as you said, Undo is limited to 100 elements, so nothing of this can justify allocation of up to 4GB!

    T.

Index: src/frontends/qt4/LayoutBox.h
===================================================================
--- src/frontends/qt4/LayoutBox.h	(revisione 39791)
+++ src/frontends/qt4/LayoutBox.h	(copia locale)
@@ -35,6 +35,7 @@
 	Q_OBJECT
 public:
 	LayoutBox(GuiView &);
+	~LayoutBox();
 
 	/// select the right layout in the combobox.
 	void set(docstring const & layout);
Index: src/frontends/qt4/GuiView.cpp
===================================================================
--- src/frontends/qt4/GuiView.cpp	(revisione 39791)
+++ src/frontends/qt4/GuiView.cpp	(copia locale)
@@ -511,6 +511,10 @@
 
 GuiView::~GuiView()
 {
+	ToolbarMap::iterator it = d.toolbars_.begin();
+	for (; it != d.toolbars_.end(); ++it)
+		delete it->second;
+	d.toolbars_.clear();
 	delete &d;
 }
 
Index: src/frontends/qt4/GuiViewSource.cpp
===================================================================
--- src/frontends/qt4/GuiViewSource.cpp	(revisione 39791)
+++ src/frontends/qt4/GuiViewSource.cpp	(copia locale)
@@ -78,6 +78,10 @@
 }
 
 
+ViewSourceWidget::~ViewSourceWidget() {
+}
+
+
 static size_t crcCheck(docstring const & s)
 {
 	boost::crc_32_type crc;
@@ -205,6 +209,7 @@
 
 GuiViewSource::~GuiViewSource()
 {
+	setWidget(0);
 	delete widget_;
 }
 
Index: src/frontends/qt4/GuiApplication.cpp
===================================================================
--- src/frontends/qt4/GuiApplication.cpp	(revisione 39791)
+++ src/frontends/qt4/GuiApplication.cpp	(copia locale)
@@ -762,6 +762,18 @@
 #ifdef Q_WS_MACX
 	closeAllLinkBackLinks();
 #endif
+	if (d->language_model_)
+		delete d->language_model_;
+	QHash<int, SocketNotifier *>::const_iterator it = d->socket_notifiers_.begin();
+	for (; it != d->socket_notifiers_.end(); ++it) {
+		unregisterSocketCallback(it.key());
+		delete it.value();
+	}
+	d->socket_notifiers_.clear();
+	if (d->global_menubar_) {
+		delete d->global_menubar_;
+		d->global_menubar_ = 0;
+	}
 	delete d;
 }
 
@@ -2280,6 +2292,7 @@
 	foreach (GuiView * view, views) {
 		if (!view->closeScheduled())
 			return false;
+		delete view;
 	}
 
 	d->views_.clear();
Index: src/frontends/qt4/TocModel.cpp
===================================================================
--- src/frontends/qt4/TocModel.cpp	(revisione 39791)
+++ src/frontends/qt4/TocModel.cpp	(copia locale)
@@ -261,11 +261,19 @@
 	names_->clear();
 	names_->blockSignals(false);
 	iterator end = models_.end();
-	for (iterator it = models_.begin(); it != end;  ++it)
+	for (iterator it = models_.begin(); it != end;  ++it) {
 		it.value()->clear();
+		delete it.value();
+	}
+	models_.clear();
 }
 
 
+TocModels::~TocModels() {
+	clear();
+}
+
+
 int TocModels::depth(QString const & type)
 {
 	const_iterator it = models_.find(type);
Index: src/frontends/qt4/TocModel.h
===================================================================
--- src/frontends/qt4/TocModel.h	(revisione 39791)
+++ src/frontends/qt4/TocModel.h	(copia locale)
@@ -111,6 +111,8 @@
 	///
 	TocModels();
 	///
+	~TocModels();
+	///
 	void reset(BufferView const * bv);
 	///
 	int depth(QString const & type);
Index: src/frontends/qt4/GuiFontLoader.cpp
===================================================================
--- src/frontends/qt4/GuiFontLoader.cpp	(revisione 39791)
+++ src/frontends/qt4/GuiFontLoader.cpp	(copia locale)
@@ -233,6 +233,7 @@
 FontLoader::~FontLoader()
 {
 	update();
+	QFontDatabase::removeAllApplicationFonts();
 }
 
 /////////////////////////////////////////////////
Index: src/frontends/qt4/GuiViewSource.h
===================================================================
--- src/frontends/qt4/GuiViewSource.h	(revisione 39791)
+++ src/frontends/qt4/GuiViewSource.h	(copia locale)
@@ -39,6 +39,8 @@
 public:
 	ViewSourceWidget();
 	///
+	~ViewSourceWidget();
+	///
 	void setBufferView(BufferView const * bv);
 
 public Q_SLOTS:
Index: src/frontends/qt4/LayoutBox.cpp
===================================================================
--- src/frontends/qt4/LayoutBox.cpp	(revisione 39791)
+++ src/frontends/qt4/LayoutBox.cpp	(copia locale)
@@ -418,6 +418,11 @@
 }
 
 
+LayoutBox::~LayoutBox() {
+	delete d;
+}
+
+
 void LayoutBox::Private::countCategories()
 {
 	int n = filterModel_->rowCount();

Reply via email to