From: Thomas L. <ta...@ec...> - 2002-05-29 17:50:42
|
I'm still trying to track down the memory leak when setting the pinboard backdrop... Can anyone see what's wrong with this code? It creates a new pixbuf image and then, once a second, renders it as a pixmap and sets it as the window's background image. On my system (Debian/Unstable, XFree86 4.1) it will sit there not doing much, but if you drag a window over it (to cause redrawing) then the X server's memory starts to increase (about 1 Mb per second while dragging). Stop dragging, and the memory stops increasing until you start again. Quitting the program and starting it again, it continues eating memory where it left off (ie, you don't get the memory back!). Now: - Have I missed something obvious? - Does this happen for everyone, or is it just me? - Why only when redrawing the window AND changing the backdrop (remove either and it works fine). - Unreffing the pixmap after setting the style causes a segfault, so I take that as a hint that we shouldn't do that. #include <gtk/gtk.h> GdkPixbuf *pixbuf = NULL; static gboolean set_background(GtkWidget *win) { GtkStyle *style; GdkPixmap *pixmap; gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap, NULL, 0); style = gtk_style_new(); style->bg_pixmap[GTK_STATE_NORMAL] = pixmap; gtk_widget_set_style(win, style); g_object_unref(style); return TRUE; } int main(int argc, char **argv) { GtkWidget *win; gtk_init(&argc, &argv); pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 800, 800); win = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_widget_set_size_request(win, gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf)); gtk_widget_show(win); g_timeout_add(1000, (GSourceFunc) set_background, win); gtk_main(); return 0; } Puzzled, but possibly just need more sleep... -- Thomas Leonard http://rox.sourceforge.net ta...@ec... ta...@us... |