[Glade-devel] memory problems using libglade2
- From: bdrs compuserve com (Bas Driessen)
- Subject: [Glade-devel] memory problems using libglade2
- Date: Tue, 11 Feb 2003 11:29:25 +1000
This is a multi-part message in MIME format.
------=_NextPart_000_0014_01C2D1C0.D7B562F0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Hello All,
I am using libglade for displaying screens in my applications. This
whole concept works great, however I have a memory problem. It appears
that libglade keeps on using more memory while running the application
and it appears that it never releases any memory when closing screens
for instance. I have created a small reproducible below and I hope
somebody can help me find the problem.
I am using RedHat Linux 8.0 with glade 1.1.3 and libglade 2.0.1
The test application does the following. It opens a screen with a
button. By pressing the button it opens a 2nd screen with a button. By
pressing that button the 2nd screen is destroyed and screen1 is the
active screen again.
Open a 2nd terminal window and run a tool as "top" for instance. On my
machine the %MEM starts at 4.2 and after it opening and closing the
screen in my test application it goes relatively quickly up to 5 and
further. I realize that this is a small test application, but with my
big application, memory is filling up in very quick.
I hope that or anyone can point me out the problem in my (small piece
of) source code below, or confirm that there are memory problems to be
expected when using libglade.
Thanks,
Bas.
========= PROGRAM ============
#include <gtk/gtk.h>
#include <glade/glade.h>
#include <glade/glade-build.h>
void on_screen1_button_clicked (GtkObject *object, gpointer user_data)
{
GladeXML *xml;
xml = glade_xml_new("./screen2.glade", NULL, NULL);
if (!xml)
{
g_warning("Something bad happened while creating the
interface");
return;
}
/* Connect signals */
glade_xml_signal_autoconnect(xml);
}
void on_screen2_button_clicked (GtkObject *object, gpointer user_data)
{
GladeXML *xml;
GtkWidget *wdgt;
xml = glade_get_widget_tree(GTK_WIDGET(object));
wdgt = glade_xml_get_widget(xml, (const gchar *)"screen2");
if(wdgt == NULL)
g_warning ("Widget not found: %s", "screen2");
gtk_widget_destroy(wdgt);
/* Do I need that here ?? */
g_object_unref(G_OBJECT(xml));
}
int main(int argc, char *argv[])
{
GladeXML *xml;
/* Set Locale */
gtk_set_locale();
/* Init GTK */
gtk_init(&argc, &argv);
xml = glade_xml_new("./screen1.glade", NULL, NULL);
if (!xml)
{
g_warning("Something bad happened while creating the
interface");
return 1;
}
/* Connect signals */
glade_xml_signal_autoconnect(xml);
/* Free object */
g_object_unref(G_OBJECT(xml));
/* Start GTK loop */
gtk_main();
return 0;
}
============= GLADE FILE SCREEN 1 ============
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "
<http://glade.gnome.org/glade-2.0.dtd>
http://glade.gnome.org/glade-2.0.dtd">
<glade-interface>
<widget class="GtkWindow" id="screen1">
<property name="visible">True</property>
<property name="title" translatable="yes">Screen 1</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">False</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<child>
<widget class="GtkFixed" id="fixed1">
<property name="visible">True</property>
<child>
<widget class="GtkButton" id="button2">
<property name="width_request">120</property>
<property name="height_request">80</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-quit</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<signal name="clicked" handler="gtk_main_quit"
last_modification_time="Fri, 07 Feb 2003 05:24:22 GMT"/>
</widget>
<packing>
<property name="x">120</property>
<property name="y">152</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="button1">
<property name="width_request">104</property>
<property name="height_request">72</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Screen 2</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<signal name="clicked" handler="on_screen1_button_clicked"
last_modification_time="Fri, 07 Feb 2003 05:25:33 GMT"/>
</widget>
<packing>
<property name="x">120</property>
<property name="y">48</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>
============= GLADE FILE SCREEN 2 ============
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "
<http://glade.gnome.org/glade-2.0.dtd>
http://glade.gnome.org/glade-2.0.dtd">
<glade-interface>
<widget class="GtkWindow" id="screen2">
<property name="visible">True</property>
<property name="title" translatable="yes">Screen 2</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">False</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<child>
<widget class="GtkFixed" id="fixed1">
<property name="visible">True</property>
<child>
<widget class="GtkButton" id="button1">
<property name="width_request">160</property>
<property name="height_request">128</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-close</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<signal name="clicked" handler="on_screen2_button_clicked"
last_modification_time="Fri, 07 Feb 2003 05:26:42 GMT"/>
</widget>
<packing>
<property name="x">88</property>
<property name="y">72</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>
------=_NextPart_000_0014_01C2D1C0.D7B562F0
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">
<TITLE>Message</TITLE>
<META content=3D"MSHTML 6.00.2800.1126" name=3DGENERATOR></HEAD>
<BODY>
<DIV><FONT face=3DTahoma size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D686240406-07022003>Hello=20
All,</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D686240406-07022003></SPAN></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D686240406-07022003>I am =
using libglade=20
for displaying screens in my applications. This whole concept works =
great,=20
however I have a memory problem. It appears that =
libglade keeps on=20
using more memory while running the application and it appears that it =
never=20
releases any memory when closing screens for instance. I have created a =
small=20
reproducible below and I hope somebody can help me find the problem.=20
</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D686240406-07022003></SPAN></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D686240406-07022003>I am =
using RedHat=20
Linux 8.0 with glade 1.1.3 and libglade 2.0.1</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D686240406-07022003></SPAN></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D686240406-07022003>The =
test application=20
does the following. It opens a screen with a button. By pressing the =
button it=20
opens a 2nd screen with a button. By pressing that button the 2nd screen =
is=20
destroyed and screen1 is the active screen again.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D686240406-07022003></SPAN></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D686240406-07022003>Open a =
2nd terminal=20
window and run a tool as "top" for instance. On my machine the %MEM =
starts at=20
4.2 and after it opening and closing the screen in my test application =
it goes=20
relatively quickly up to 5 and further. I realize that this is a small =
test=20
application, but with my big application, memory is filling up in very=20
quick.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D686240406-07022003></SPAN></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D686240406-07022003>I hope =
that or=20
anyone can point me out the problem in my (small piece of) source code =
below, or=20
confirm that there are memory problems to be expected when using=20
libglade.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D686240406-07022003></SPAN></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D686240406-07022003>Thanks,</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D686240406-07022003></SPAN></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D686240406-07022003>Bas.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D686240406-07022003></SPAN></FONT><FONT=20
face=3DArial size=3D2><SPAN =
class=3D686240406-07022003></SPAN></FONT><FONT face=3DArial=20
size=3D2><SPAN class=3D686240406-07022003></SPAN></FONT><FONT =
face=3DArial=20
size=3D2><SPAN class=3D686240406-07022003></SPAN></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT><FONT face=3DArial =
size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><SPAN class=3D686240406-07022003><FONT face=3DArial =
size=3D2>=3D=3D=3D=3D=3D=3D=3D=3D=3D PROGRAM=20
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</FONT></SPAN></DIV>
<DIV><SPAN class=3D686240406-07022003><FONT face=3DArial=20
size=3D2></FONT></SPAN> </DIV>
<DIV><FONT face=3DArial size=3D2>#include <gtk/gtk.h><BR>#include=20
<glade/glade.h><BR>#include =
<glade/glade-build.h></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>void on_screen1_button_clicked =
(GtkObject *object,=20
gpointer user_data)<BR>{<BR> =
GladeXML=20
*xml;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial =
size=3D2> xml =3D=20
glade_xml_new("./screen2.glade", NULL,=20
NULL);<BR> if=20
(!xml)<BR> =20
{<BR> &n=
bsp; =20
g_warning("Something bad happened while creating the=20
interface");<BR> &nb=
sp; =20
return;<BR> }</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial =
size=3D2> /*=20
Connect signals */<BR> =20
glade_xml_signal_autoconnect(xml);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>void on_screen2_button_clicked =
(GtkObject *object,=20
gpointer user_data)<BR>{<BR> =
GladeXML=20
*xml;<BR> GtkWidget=20
*wdgt;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial =
size=3D2> xml =3D=20
glade_get_widget_tree(GTK_WIDGET(object));</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial =
size=3D2> wdgt =3D=20
glade_xml_get_widget(xml, (const gchar *)"screen2");</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial =
size=3D2> if(wdgt=20
=3D=3D=20
NULL)<BR> &nbs=
p; =20
g_warning ("Widget not found: %s", "screen2");</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial =
size=3D2> =20
gtk_widget_destroy(wdgt);<BR> =20
</FONT></DIV>
<DIV><SPAN class=3D686240406-07022003><FONT face=3DArial=20
size=3D2> /* Do I need =
that here=20
?? */</FONT></SPAN></DIV>
<DIV><SPAN class=3D686240406-07022003><FONT face=3DArial=20
size=3D2> =
</FONT></SPAN><FONT=20
face=3DArial size=3D2>g_object_unref(G_OBJECT(xml));<BR>}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><BR><FONT face=3DArial size=3D2>int main(int argc, char=20
*argv[])<BR>{<BR> GladeXML=20
*xml;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial =
size=3D2> /* Set=20
Locale */<BR> =20
gtk_set_locale();</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial =
size=3D2> /* Init=20
GTK */<BR> gtk_init(&argc, =
&argv);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial =
size=3D2> xml =3D=20
glade_xml_new("./screen1.glade", NULL,=20
NULL);<BR> if=20
(!xml)<BR> =20
{<BR> &n=
bsp; =20
g_warning("Something bad happened while creating the=20
interface");<BR> &nb=
sp; =20
return 1;<BR> }</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial =
size=3D2> /*=20
Connect signals */<BR> =20
glade_xml_signal_autoconnect(xml);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial =
size=3D2> /* Free=20
object */<BR> =20
g_object_unref(G_OBJECT(xml));</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial =
size=3D2> /* Start=20
GTK loop */<BR> =20
gtk_main();</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial =
size=3D2> return=20
0;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><SPAN class=3D686240406-07022003><FONT face=3DArial =
size=3D2>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D GLADE=20
FILE SCREEN 1 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</FONT></SPAN></DIV>
<DIV><FONT face=3DArial size=3D2></FONT><BR><FONT face=3DArial =
size=3D2><?xml=20
version=3D"1.0" standalone=3D"no"?> <!--*- mode: xml =
-*--><BR><!DOCTYPE=20
glade-interface SYSTEM "</FONT><A=20
href=3D"http://glade.gnome.org/glade-2.0.dtd"><FONT face=3DArial=20
size=3D2>http://glade.gnome.org/glade-2.0.dtd</FONT></A><FONT =
face=3DArial=20
size=3D2>"></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><glade-interface></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><widget class=3D"GtkWindow"=20
id=3D"screen1"><BR> <property=20
name=3D"visible">True</property><BR> <property =
name=3D"title"=20
translatable=3D"yes">Screen 1</property><BR> <property =
name=3D"type">GTK_WINDOW_TOPLEVEL</property><BR> =
<property=20
name=3D"window_position">GTK_WIN_POS_NONE</property><BR> =20
<property name=3D"modal">False</property><BR> =
<property=20
name=3D"resizable">True</property><BR> <property=20
name=3D"destroy_with_parent">False</property></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> =
<child><BR> =20
<widget class=3D"GtkFixed" =
id=3D"fixed1"><BR> =20
<property name=3D"visible">True</property></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> =20
<child><BR> <widget=20
class=3D"GtkButton"=20
id=3D"button2"><BR> &nb=
sp;=20
<property=20
name=3D"width_request">120</property><BR>  =
; =20
<property=20
name=3D"height_request">80</property><BR>  =
; =20
<property=20
name=3D"visible">True</property><BR> &nbs=
p; =20
<property=20
name=3D"can_focus">True</property><BR> &n=
bsp; =20
<property=20
name=3D"label">gtk-quit</property><BR> &n=
bsp; =20
<property=20
name=3D"use_stock">True</property><BR> &n=
bsp; =20
<property=20
name=3D"relief">GTK_RELIEF_NORMAL</property><BR> &nbs=
p; =20
<signal name=3D"clicked" handler=3D"gtk_main_quit" =
last_modification_time=3D"Fri,=20
07 Feb 2003 05:24:22 =
GMT"/><BR> =20
</widget><BR> =20
<packing><BR> =
=20
<property=20
name=3D"x">120</property><BR>  =
; =20
<property=20
name=3D"y">152</property><BR>  =
; =20
</packing><BR> =
</child></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> =20
<child><BR> <widget=20
class=3D"GtkButton"=20
id=3D"button1"><BR> &nb=
sp;=20
<property=20
name=3D"width_request">104</property><BR>  =
; =20
<property=20
name=3D"height_request">72</property><BR>  =
; =20
<property=20
name=3D"visible">True</property><BR> &nbs=
p; =20
<property=20
name=3D"can_focus">True</property><BR> &n=
bsp; =20
<property name=3D"label" translatable=3D"yes">Screen=20
2</property><BR> &nb=
sp;=20
<property=20
name=3D"use_underline">True</property><BR> &nbs=
p; =20
<property=20
name=3D"relief">GTK_RELIEF_NORMAL</property><BR> &nbs=
p; =20
<signal name=3D"clicked" handler=3D"on_screen1_button_clicked"=20
last_modification_time=3D"Fri, 07 Feb 2003 05:25:33=20
GMT"/><BR> =20
</widget><BR> =20
<packing><BR> =
=20
<property=20
name=3D"x">120</property><BR>  =
; =20
<property=20
name=3D"y">48</property><BR> =
=20
</packing><BR> =20
</child><BR> </widget><BR> =20
</child><BR></widget></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></glade-interface></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D686240406-07022003><FONT =
face=3DArial=20
size=3D2>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D GLADE FILE =
SCREEN 2=20
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</FONT></SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><?xml version=3D"1.0" =
standalone=3D"no"?>=20
<!--*- mode: xml -*--><BR><!DOCTYPE glade-interface SYSTEM =
"</FONT><A=20
href=3D"http://glade.gnome.org/glade-2.0.dtd"><FONT face=3DArial=20
size=3D2>http://glade.gnome.org/glade-2.0.dtd</FONT></A><FONT =
face=3DArial=20
size=3D2>"></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><glade-interface></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><widget class=3D"GtkWindow"=20
id=3D"screen2"><BR> <property=20
name=3D"visible">True</property><BR> <property =
name=3D"title"=20
translatable=3D"yes">Screen 2</property><BR> <property =
name=3D"type">GTK_WINDOW_TOPLEVEL</property><BR> =
<property=20
name=3D"window_position">GTK_WIN_POS_NONE</property><BR> =20
<property name=3D"modal">False</property><BR> =
<property=20
name=3D"resizable">True</property><BR> <property=20
name=3D"destroy_with_parent">False</property></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> =
<child><BR> =20
<widget class=3D"GtkFixed" =
id=3D"fixed1"><BR> =20
<property name=3D"visible">True</property></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> =20
<child><BR> <widget=20
class=3D"GtkButton"=20
id=3D"button1"><BR> &nb=
sp;=20
<property=20
name=3D"width_request">160</property><BR>  =
; =20
<property=20
name=3D"height_request">128</property><BR> &nbs=
p; =20
<property=20
name=3D"visible">True</property><BR> &nbs=
p; =20
<property=20
name=3D"can_focus">True</property><BR> &n=
bsp; =20
<property=20
name=3D"label">gtk-close</property><BR> &=
nbsp; =20
<property=20
name=3D"use_stock">True</property><BR> &n=
bsp; =20
<property=20
name=3D"relief">GTK_RELIEF_NORMAL</property><BR> &nbs=
p; =20
<signal name=3D"clicked" handler=3D"on_screen2_button_clicked"=20
last_modification_time=3D"Fri, 07 Feb 2003 05:26:42=20
GMT"/><BR> =20
</widget><BR> =20
<packing><BR> =
=20
<property=20
name=3D"x">88</property><BR> =
=20
<property=20
name=3D"y">72</property><BR> =
=20
</packing><BR> =20
</child><BR> </widget><BR> =20
</child><BR></widget></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial =
size=3D2></glade-interface></FONT></DIV></BODY></HTML>
------=_NextPart_000_0014_01C2D1C0.D7B562F0--
[Date Prev][
Date Next] [Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]