webkitwebkitgtk

WebKitGTK about webkit_web_view_load_uri


I have a question about WebktGTK.

These days I am making a program which is can analysis web page if has suspicious web content.

When "load-failed" "load-changed" signal is emitted with WEBKIT_LOAD_FINISHED, The program anlaysis the next page continuously by calling webkit_web_view_load_uri again again.

(http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#webkit-web-view-load-uri)

The question want to ask you is memory problem. The more the program analsysis the webpages, The more WebKitWebProcess is bigger.

webkit_back_forward_list_get_length() return value also increased by analysising web pages. Where shoud I free memory?

Do you know how Can I solve this problem or Could give me any advice where Can I get advice?

Thank you very much :-) Have a nice day ^^


Solution

  • In theory, what you're doing is perfectly fine, and you shouldn't need to change your code at all. In practice, WebKit has a lot of memory leaks, and programatically loading many new URIs in the same web view is eventually going to be problematic, as you've found.

    My recommendation is to periodically, every so many page loads, create a new web view that uses a separate web process, and destroy the original web view. (That will also reset the back/forward list to stop it from growing, though I suspect the memory lost to the back/forward list is probably not significant compared to memory leaks when rendering the page.) I filed Bug 151203 - [GTK] Start a new web process when calling webkit_web_view_load functions? to consider having this happen automatically; your issue indicates we may need to bump the priority on that. In the meantime, you'll have to do it manually:

    If you have trouble getting that solution to work, an extreme alternative would be to periodically send SIGTERM to your web process to get a new one. Connect to WebKitWebView::web-process-crashed, and call webkit_web_view_load_uri() from there. That will result in the same web view using a new web process.