[webkit-gtk] Memory leaks creating and removing webviews
Josh Rickmar
jrick at devio.us
Wed Jun 12 11:49:38 PDT 2013
This issue may have already been beaten to death, but I am seeing
pretty bad memory leaks when creating, showing and, and then deleting
WebKitWebView widgets. I've written and attached a very small test
browser that will open tabs to Google's homepage, with a button on
each tab to remove the tab and free everything in that notebook's
page's container. From what I can observe with top, I lose roughly 3
MB per each tab open and close.
From what I can tell based on the GTK and WebKitGtk docs, I am
managing all the memory correctly even with this small test browser.
If I am doing anything incorrect that may help with the leaks, please
let me know. Otherwise, what parts of the Webkit or WebKitGtk code
should be examined first for leaks?
--
Josh Rickmar
http://jrick.devio.us/
-------------- next part --------------
#include <gtk/gtk.h>
#include <webkit/webkit.h>
typedef struct {
GtkNotebook *nb;
GtkWidget *child;
} close_btn_args;
void
close_btn_cb(GtkButton *btn, gpointer user_data)
{
close_btn_args *args = (close_btn_args *)user_data;
GtkNotebook *nb = args->nb;
GtkWidget *wv = args->child;
gint pn;
if ((pn = gtk_notebook_page_num(nb, wv)) != -1)
gtk_notebook_remove_page(nb, pn);
g_free(args);
}
void
new_tab(GtkNotebook *nb)
{
GtkWidget *b;
GtkWidget *close_btn;
GtkWidget *wv;
close_btn_args *args;
wv = webkit_web_view_new();
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(wv),
"https://www.google.com/");
g_object_ref_sink(G_OBJECT(wv));
close_btn = gtk_button_new();
gtk_button_set_image(GTK_BUTTON(close_btn), gtk_image_new_from_stock
(GTK_STOCK_CLOSE, GTK_ICON_SIZE_SMALL_TOOLBAR));
args = g_malloc0(sizeof *args);
args->nb = nb;
args->child = wv;
g_signal_connect(close_btn, "clicked", G_CALLBACK(close_btn_cb), args);
b = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 1);
gtk_box_pack_start(GTK_BOX(b), close_btn, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(b), gtk_label_new("Tab Label"), FALSE,
FALSE, 0);
gtk_widget_show_all(b);
gtk_notebook_append_page(nb, wv, b);
gtk_widget_show_all(GTK_WIDGET(nb));
}
void
nt_btn_cb(GtkButton *btn, gpointer user_data)
{
GtkNotebook *nb = GTK_NOTEBOOK(user_data);
new_tab(nb);
}
int
main(int argc, char **argv)
{
GtkWidget *win;
GtkWidget *nb;
GtkWidget *nt_btn;
gtk_init(&argc, &argv);
win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(win, "destroy",
G_CALLBACK(gtk_main_quit), NULL);
nb = gtk_notebook_new();
gtk_container_add(GTK_CONTAINER(win), nb);
new_tab(GTK_NOTEBOOK(nb));
nt_btn = gtk_button_new();
gtk_button_set_image(GTK_BUTTON(nt_btn), gtk_image_new_from_stock
(GTK_STOCK_NEW, GTK_ICON_SIZE_MENU));
g_signal_connect(nt_btn, "clicked", G_CALLBACK(nt_btn_cb), nb);
gtk_notebook_set_action_widget(GTK_NOTEBOOK(nb), nt_btn,
GTK_PACK_START);
gtk_widget_show(nt_btn);
gtk_widget_show_all(win);
gtk_main();
return (0);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 2527 bytes
Desc: not available
URL: <http://lists.webkit.org/pipermail/webkit-gtk/attachments/20130612/21be4ecc/attachment.bin>
More information about the webkit-gtk
mailing list