1
我正在試驗WebkitGTK。使用WebkitGTK泄露
LEAK: 1 CachedResource
LEAK: 12 WebCoreNode
的WebkitGTK程序是一個簡單的C程序:
#include <gtk/gtk.h>
#include <webkit/webkit.h>
#include <stdio.h>
static void load_status_callback(GObject* object, GParamSpec* pspec, void* window)
{
WebKitWebView* view = WEBKIT_WEB_VIEW(object);
WebKitLoadStatus status = webkit_web_view_get_load_status(view);
switch (status)
{
case WEBKIT_LOAD_FINISHED:
{
printf("WEBKIT_LOAD_FINISHED\n");
gtk_main_quit();
break;
}
default: g_assert_not_reached();
}
};
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv);
GtkWidget *main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(main_window), 800, 600);
WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
GtkWidget *scrolledWindow = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledWindow),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_container_add(GTK_CONTAINER(scrolledWindow), GTK_WIDGET(webView));
g_signal_connect(webView, "notify::load-status", G_CALLBACK(load_status_callback), main_window);
gtk_container_add(GTK_CONTAINER(main_window), scrolledWindow);
webkit_web_view_load_uri(webView, "http://127.0.0.1/test.html");
gtk_widget_grab_focus(GTK_WIDGET(webView));
gtk_widget_show_all(main_window);
gtk_main(); // Run main event loop
gtk_widget_destroy(main_window);
return 0;
}
使用一個簡單的「Hello World」風格的應用程序,什麼也不做,但下載的網頁,然後退出,WebKit的報告運行該程序後泄漏的對象
我下載HTML很簡單:
<html>
<head>
<script type = "text/javascript"></script>
</head>
<body>
<div id = "foo"></div>
</body>
</html>
一些實驗後,我發現,如果我刪除<script>
標籤,這使得泄漏不會發生我相信我應該做些什麼來關閉JavaScriptCore。那麼,爲什麼WebKit報告泄漏?