Search code examples
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:

    • Before doing anything else in your application, set the process model to WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES using webkit_web_context_set_process_model(). (If you are not creating your own web contexts, you'll need to use the default web context webkit_web_context_get_default().)
    • Periodically destroy your web view with gtk_widget_destroy(), then create a new one using webkit_web_view_new() et. al. and attach it somewhere in your widget hierarchy. (Be sure NOT to use webkit_web_view_new_with_related_view() as that's how you get two web views to use the same web process.)

    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.