Clearing caches on system signal

Currently, I'm experimenting with WebKit to release all the memory what we can on given conditions. This can be useful in low memory situations or when the system goes asleep (less RAM usage needs less power).

WebKit uses caching mechanisms to keep downloaded data in the memory since it is common that those will be asked again in the same browsing session. However, it is safe to clear these caches if memory is needed for other purposes. The API of QtWebKit offers this clearing functionality through the (static) QWebSettings::clearMemoryCaches method. What we need is a way to listen for system events. Now, I'm experimenting with DBus, a lightweight IPC solution on Linux and other Unix-like systems. Unfortunately, I have not found a standard memory usage watchdog that would signal apps when memory is low. However, the Maemo platform uses DBus for lots of things. There are signals for charging, inactivity (when the system goes asleep), and other things.

So, I implemented a DBus-based memory release solution for QtWebKit. For the sake of experiment, in the midst of a browsing session I sent out a DBus message. Parallely, I monitored the memory usage of WebKit as well, and as a response to the message, the highest drop in memory consumption what I measured was about 2 MB . (The total memory usage of WebKit was about 38 MB before the message, so it's about a 5% reduction.) The measurement based on glibc's mallinfo function - the uordblks field in the returned structure.

Here is the staff below as a patch with a demo signal sender.

clearcachesslot_forblog.diff1.63 KB
Send.cpp914 bytes

Kenneth Christiansen (not verified) - 07/27/2009 - 16:50

You dont need to patch webkit for doing this :-), you can easily do this from the application site!

balazs.kelemen - 07/27/2009 - 18:05

You are absolutely right.
How could it escape my attention?...

Luying (not verified) - 10/22/2009 - 15:14

What did Kenneth mean by application site? Can somebody elaborate?

balazs.kelemen - 10/22/2009 - 16:36

You can do it in the application that uses WebKit without changes in the lib, for example you can do it in QtLauncher (WebKit/qt/QtLauncher/main.cpp).

Gabor Torok (not verified) - 12/09/2010 - 19:02

But it DOES make sense to add this feature to the lib and not burden application writers to implement it over and over again. This feature could be disabled by default and enabled upon explicit request. (not verified) - 05/11/2015 - 03:18

Love it! Very interesting topics, I hope the incoming comments and suggestion are equally positive. Thank you for sharing this information that is actually helpful.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • No HTML tags allowed
  • Lines and paragraphs break automatically.

More information about formatting options

This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Fill in the blank