* gtk-container-children memory leak
@ 2003-01-24 15:05 Kevin Ryde
2003-06-19 1:14 ` Kevin Ryde
0 siblings, 1 reply; 2+ messages in thread
From: Kevin Ryde @ 2003-01-24 15:05 UTC (permalink / raw)
To: guile-gtk
I think gtk-container-children might be leaking memory. On a recent
i386 debian and my build of guile 1.6.1, the following little program
uses an apparently ever increasing amount of core (as shown by the
"top" program).
(use-modules (gtk gtk))
(define toplevel (gtk-window-new 'toplevel))
(gtk-container-add toplevel (gtk-label-new "foo"))
(while #t
(gtk-container-children toplevel))
I think gtk_container_children allocates a fresh GList for its return,
which the caller is supposed to free. As far as I can tell that
doesn't happen in gtk-glue.c etc.
Inserting a g_list_free manually into sgtk_gtk_container_children
seems to do the trick, but I'm not smart enough to tell how to get
that done properly.
It'd probably be good to allow either freeing or not.
gtk_container_children and a prospective gdk_list_visuals should free,
gtk_radio_button_group (which is a GSList) and a prospective
gdk_window_peek_children (implementing gtk-window-children) shouldn't.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: gtk-container-children memory leak
2003-01-24 15:05 gtk-container-children memory leak Kevin Ryde
@ 2003-06-19 1:14 ` Kevin Ryde
0 siblings, 0 replies; 2+ messages in thread
From: Kevin Ryde @ 2003-06-19 1:14 UTC (permalink / raw)
To: guile-gtk
[-- Attachment #1: Type: text/plain, Size: 685 bytes --]
I wrote:
>
> I think gtk-container-children might be leaking memory.
I propose to free the returned list with the following change.
* gtk-support.c (_sgtk_helper_toscm_copy_GtkWidget): New function.
* gtk-support.c, guile-gtk.h (gtk_container_children_interp): New
function.
* gdk-1.2.defs (gtk_container_children): Use it.
This change fixes a memory leak in gtk-container-children, the GList
returned by gtk_container_children must be freed by the caller.
I suppose I could use _sgtk_helper_toscm_copy_GtkWidget from the glue
file if it wasn't static. The name would be ok to be a global. Easy
enough to duplicate for now though.
[-- Attachment #2: gtk-support.c.container-children.diff --]
[-- Type: text/plain, Size: 1029 bytes --]
--- gtk-support.c.~1.6.~ 2003-05-08 08:03:54.000000000 +1000
+++ gtk-support.c 2003-06-15 16:10:38.000000000 +1000
@@ -160,6 +160,30 @@
gtk_selection_data_data (GtkSelectionData* data)
{ return (data->length >= 0) ? scm_mem2string (data->data, data->length) : SCM_BOOL_F; }
+
+/* Same as in gtk-glue.c, could share with that file if it exported this. */
+static SCM
+_sgtk_helper_toscm_copy_GtkWidget (void *mem)
+{
+ return sgtk_wrap_gtkobj ((GtkObject*)(*(GtkWidget**)mem));
+}
+
+/* The list returned by gtk_container_children must be freed by the caller.
+ Could do this sort of thing with a .defs file option, but easy enough to
+ have explicit code while there's only a few such. */
+SCM
+gtk_container_children_interp (GtkContainer *container)
+{
+ GList* children;
+ SCM ret;
+ children = gtk_container_children (container);
+ ret = sgtk_list2scm (children, _sgtk_helper_toscm_copy_GtkWidget);
+ g_list_free (children);
+ return ret;
+}
+
+
+
\f
/* These SCM_PROCs are here to have them initialized in
[-- Attachment #3: guile-gtk.h.container-children.diff --]
[-- Type: text/plain, Size: 363 bytes --]
--- guile-gtk.h.~1.25.~ 2003-06-15 09:08:11.000000000 +1000
+++ guile-gtk.h 2003-06-15 16:11:10.000000000 +1000
@@ -322,6 +322,7 @@
typedef int GtkWidgetFlags;
#endif
+SCM gtk_container_children_interp (GtkContainer *container);
gchar *gtk_label_get_interp (GtkLabel *label);
void gtk_menu_popup_interp (GtkMenu *menu,
GtkWidget *parent_menu_shell,
[-- Attachment #4: gtk-1.2.defs.container-children.diff --]
[-- Type: text/plain, Size: 398 bytes --]
--- gtk-1.2.defs.~1.10.~ 2003-04-04 08:07:41.000000000 +1000
+++ gtk-1.2.defs 2003-06-15 16:08:51.000000000 +1000
@@ -888,8 +888,8 @@
(scm-name "gtk-container-foreach-full")
(protection #t))
-(define-func gtk_container_children
- ((list GtkWidget))
+(define-func gtk_container_children_interp
+ SCM ;; list of GtkWidget
((GtkContainer container)))
(define-func gtk_container_focus
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-06-19 1:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-24 15:05 gtk-container-children memory leak Kevin Ryde
2003-06-19 1:14 ` Kevin Ryde
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).