[webkit-dev] caching /memory leak... browsing images

Purushottam Sholapur purushottam.sholapur at gmail.com
Mon Mar 23 07:02:33 PDT 2009


After debugging, I could find some memory leak/optimization that is
possible.

Files:
qt-embedded-linux-opensource-src-4.5.0/src/3rdparty/webkit/WebCore/platform/graphics/qt/ImageDecoderQt.cpp
and .h

In QImageDecodeQt, there is Qlist of ImageData (m_imageList), which is not
freed after its use.
Generally, with my understanding, every image is decoded and stored in this
list. Later it is converted to QPixmap. Which means there will be two copies
of decoded image, one in the list and other is Pixmap. This list image can
be freed after it is converted to Pixmap. This really saves a lot of
memory(decoded images are huge).

The only change I have made is cleaning this list. Can anybody verify this
and confirm.
Atleast, I did not see any new issue with this fix. I have verified with
valgrind on linux desktop, Now there is no memory leak for QImage.

Here is the patch.
--- ImageDecoderQt.cpp_ori      2009-03-19 13:46:04.000000000 +0530
+++ ImageDecoderQt.cpp  2009-03-23 18:54:13.000000000 +0530
@@ -303,7 +303,7 @@
     return 0;
 }

-QPixmap* ImageDecoderQt::imageAtIndex(size_t index) const
+QPixmap* ImageDecoderQt::imageAtIndex(size_t index) //const
 {
     if (debugImageDecoderQt)
         qDebug() << "ImageDecoderQt::imageAtIndex(" << index << ')';
@@ -314,6 +314,7 @@
     if (!m_pixmapCache.contains(index)) {
         m_pixmapCache.insert(index,

QPixmap::fromImage(m_imageList[index].m_image));
+             m_imageList.clear();
     }
     return  &m_pixmapCache[index];
 }

--- ImageDecoderQt.h_ori        2009-03-23 18:56:48.000000000 +0530
+++ ImageDecoderQt.h    2009-03-23 18:57:15.000000000 +0530
@@ -50,7 +50,7 @@
     virtual int repetitionCount() const;
     virtual RGBA32Buffer* frameBufferAtIndex(size_t index);

-    QPixmap* imageAtIndex(size_t index) const;
+    QPixmap* imageAtIndex(size_t index) ;
     virtual bool supportsAlpha() const;
     int duration(size_t index) const;
     virtual String filenameExtension() const;

If you want more details about valgrind memory leak statistics or how to
test, etc I can send.

regards
Purush



On Mon, Mar 16, 2009 at 3:22 PM, zaheer ahmad <zaheer.mot at gmail.com> wrote:

> Webkit has a default cache of 8 Mb (WebCore/Loader/Cache.cpp) and your data
> suggests it is using with in that limit. And it is a fraction of 150Mb you
> have mentioned, please check where the other memory is going.
>
> thanks,
> Zaheer
> On Mon, Mar 16, 2009 at 11:49 AM, Purushottam Sholapur <
> purushottam.sholapur at gmail.com> wrote:
>
>> Hi All,
>>
>> I am using webkit on davinci platform, with QT. We have 150MB of RAM,
>> If I use browser for 15-20 minutes. Entire memory is exhausted. There is
>> no other
>> application running. This is happening more with webpages having bigger
>> images. I am
>> browsing http://www.images.google.com
>>
>> I tried with QtLauncher and Qt demo/browser, behavior is same.
>> I tried with latest nightly webkit build also. (on 9th Mar '09), same
>> result.
>> Not sure where it is caching or leaking.
>>
>> Tried dumping Cache statistics periodically using.
>>     Cache * cp = cache();
>>     cp->dumpStats();
>>
>> It initially prints like this ....
>>             Count       Size        LiveSize    DecodedSize PurgeableSize
>> PurgedSize
>> ----------- ----------- ----------- ----------- ----------- -----------
>> -----------
>> Images                3      210215      210215      186976
>> 0           0
>> CSS                   0           0           0           0
>> 0           0
>> JavaScript            1        2285        2285           0
>> 0           0
>> Fonts                 0           0           0           0
>> 0           0
>> ----------- ----------- ----------- ----------- ----------- -----------
>> -----------
>> Later ....
>>             Count       Size        LiveSize    DecodedSize PurgeableSize
>> PurgedSize
>> ----------- ----------- ----------- ----------- ----------- -----------
>> -----------
>> Images               40     3968623     3891850     3729336
>> 0           0
>> CSS                   2       17409       17409           0
>> 0           0
>> JavaScript            4      651566      649281      432854
>> 0           0
>> Fonts                 0           0           0           0
>> 0           0
>> ----------- ----------- ----------- ----------- ----------- -----------
>> -----------
>>
>> Images, CSS, JavaScript count never reduces. Are they cached..?
>>
>> Is it same as that of this ...
>> http://www.nabble.com/JavaScript-memory-management-question-to20842278.html#a20842278
>>
>>
>> Please suggest to solve this,
>>
>> regards
>> Purush
>>
>>
>>
>>
>> _______________________________________________
>> webkit-dev mailing list
>> webkit-dev at lists.webkit.org
>> http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20090323/c6d875f6/attachment.html>


More information about the webkit-dev mailing list