Bug 101192 - Leaking memory when watching a file
Summary: Leaking memory when watching a file
Status: RESOLVED FIXED
Alias: None
Product: kpdf
Classification: Applications
Component: general (show other bugs)
Version: 0.4
Platform: Gentoo Packages Linux
: NOR normal
Target Milestone: ---
Assignee: Albert Astals Cid
URL:
Keywords:
: 101265 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-03-09 19:05 UTC by Kevin Goeser
Modified: 2005-04-17 01:18 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin Goeser 2005-03-09 19:05:31 UTC
Version:           0.4 (using KDE KDE 3.4.0)
Installed from:    Gentoo Packages
Compiler:          gcc-3.3.5 
OS:                Linux

While doing some tex, I used kpdf to view the results. Using "Watch File" it is reloading the file, when it changed. Somehow, it consumes more and more memory (perhaps it keeps the old versions?).

I'm not sure about the result of top (X?), so I just paste it here.
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
11506 root      15   0  304m 148m 140m S  7.7 14.6 166:59.66 X
26966 me  15   0  107m  62m  31m S  0.3  6.2   0:39.33 kpdf

After closing kpdf:
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
11506 root      15   0  226m  70m 140m S  0.3  7.0 167:00.54 X

This is the memory usage after some reloads, working a bit longer it consumes some 100mb!
Comment 1 Albert Astals Cid 2005-03-09 23:08:47 UTC
CVS commit by aacid: 

Comitting a fix for the memory leak that happens when reloading a file because it was beign watched.
To fix it what we do is close the document, show a message telling that the document is beign reloaded and then open the document again when it's ready, that presents a big problem to a backport, because without the text it is really not understood that something is happening.
Enrico any idea to do this in a better way so we can backport it?
BUGS: 101192 


  M +17 -4     part.cpp   1.30
  M +2 -1      part.h   1.11
  M +7 -0      ui/pageview.cpp   1.49
  M +2 -0      ui/pageview.h   1.17


--- kdegraphics/kpdf/part.cpp  #1.29:1.30
@@ -357,4 +357,6 @@ bool Part::openURL(const KURL &url)
     if ( !b )
         KMessageBox::error( widget(), i18n("Could not open %1").arg( url.prettyURL() ) );
+    else
+        m_viewportDirty.pageNumber = -1;
     return b;
 }
@@ -403,9 +405,20 @@ void Part::slotFileDirty( const QString&
 void Part::slotDoFileDirty()
 {
-  uint p = m_document->currentPage() + 1;
-  if (openFile())
+  if (m_viewportDirty.pageNumber == -1)
   {
-    if (p > m_document->pages()) p = m_document->pages();
-    goToPage(p);
+    m_viewportDirty = m_document->viewport();
+    m_pageView->showText(i18n("Reloading the document..."), 0);
+  }
+
+  if (KParts::ReadOnlyPart::openURL(m_file))
+  {
+    if (m_viewportDirty.pageNumber > m_document->pages()) m_viewportDirty.pageNumber = m_document->pages();
+    m_document->setViewport(m_viewportDirty);
+    m_viewportDirty.pageNumber = -1;
+  }
+  else
+  {
+    m_watcher->addFile(m_file);
+    m_dirtyHandler->start( 750, true );
   }
 }

--- kdegraphics/kpdf/part.h  #1.10:1.11
@@ -20,4 +20,5 @@
 #include <kparts/part.h>
 #include <qguardedptr.h>
+#include "core/document.h"
 #include "core/observer.h"
 #include "dcop.h"
@@ -36,5 +37,4 @@ class KAboutData;
 class KPrinter;
 
-class KPDFDocument;
 class ThumbnailList;
 class ThumbnailController;
@@ -134,4 +134,5 @@ private:
         KDirWatch *m_watcher;
         QTimer *m_dirtyHandler;
+        DocumentViewport m_viewportDirty;
 
         // actions

--- kdegraphics/kpdf/ui/pageview.cpp  #1.48:1.49
@@ -404,4 +404,11 @@ bool PageView::canUnloadPixmap( int page
 //END DocumentObserver inherited methods
 
+
+void PageView::showText( const QString &text, int ms )
+{
+    d->messageWindow->display(text, PageViewMessage::Info, ms );
+}
+
+
 //BEGIN widget events
 void PageView::viewportPaintEvent( QPaintEvent * pe )

--- kdegraphics/kpdf/ui/pageview.h  #1.16:1.17
@@ -64,4 +64,6 @@ class PageView : public QScrollView, pub
         bool canUnloadPixmap( int pageNum );
 
+        void showText( const QString &text, int ms );
+
     signals:
         void urlDropped( const KURL& );
Comment 2 Kevin Goeser 2005-03-10 12:02:19 UTC
Verified :) Thx for the fast fix!!!
To the backport: You could introduce a statusbar, showing all information displayed in the message box of the newer versions (if this is not too much for a backport).
Comment 3 Albert Astals Cid 2005-03-10 19:50:14 UTC
The problem is not the message box but the text itself, in "old" branches like KDE 3.4.x new texts are not allowed :-( and without "Reloading the document..." it is pretty difficult to see the document is actually beign reloaded.
Comment 4 Albert Astals Cid 2005-03-10 22:12:36 UTC
*** Bug 101265 has been marked as a duplicate of this bug. ***
Comment 5 Dominic Battre 2005-04-16 18:30:59 UTC
How about a backport that shows the filename of the file being reloaded instead of i18n("Reloading the document...").  Might be still unclear but maybe better than the memory leak.  And it does not need translation.

Just an idea... Keep up that great work...
Comment 6 Albert Astals Cid 2005-04-17 01:18:54 UTC
I've backported the fix with the translation asked at translators list and got an OK