[Gtk-sharp-list] Memory leakage in Expose?

muell_muell_@gmx.net muell_muell_@gmx.net
Thu, 24 Mar 2005 13:57:22 +0100


This is a multi-part message in MIME format.
--------------030505010002020005000407
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit

Hi *,
i have written an gtk-sharp application in c# and everything works fine.
My main window is filled with a Gtk.Fixed and on this, there will be
other widgets placed.

The problem: since the first widget is placed on the Gtk.Fixed the
program takes up to 90% of cpu usage and the used memory is slowly
growing up to infinity. During debugging i explored, that there are 2
exposed functions, which are always called:
the exposed function of the gtk.Fixed:
        public void rahmen_ExposeEvent(object o, Gtk.ExposeEventArgs args) {
            Gdk.Color c_inaktiv = new Gdk.Color(0, 0, 0);
            Gdk.Color c_aktiv = new Gdk.Color(255, 0, 0);
            foreach (Verbinder verb in this.verbindungen) {
                int x1, y1, x2, y2;
                verb.Von.TranslateCoordinates(this.bk, 0, 0, out x1, out
y1);
                verb.Bis.TranslateCoordinates(this.bk, 0, 0, out x2, out
y2);

                Gtk.Requisition r1 = verb.Von.SizeRequest();
                x1 += r1.Width;
                y1 +=
((verb.Von.kastenrahmen.kastenwidget.SizeRequest().Height/verb.Von.kastenrahmen.buttons_ausgabe.Count)/2);

                // Linien-Ziel-Koordinaten berechnen
                y2 +=
((verb.Bis.kastenrahmen.kastenwidget.SizeRequest().Height/verb.Bis.kastenrahmen.buttons_eingabe.Count)/2);

                if (verb.VerbindungAktiv) {
                    this.ModifyBase(Gtk.StateType.Normal, c_aktiv);
                } else {
                    this.ModifyBase(Gtk.StateType.Normal, c_inaktiv);
                }
               
this.GdkWindow.DrawLine(this.Style.BaseGC(Gtk.StateType.Normal), x1, y1,
x2, y2);
            }
        }
it runs checks a special ArrayList and calculating coordinates of a view
widgets ans draw lines between them.

the exposed funktion of the widget on the gtk.fixed:
void Kasten_ExposeEvent(object o, Gtk.ExposeEventArgs args) {
            kasten_groesse = this.SizeRequest();
            Gdk.Color c_hintergrund = new Gdk.Color(255, 255, 255);
            Gdk.Color c_rahmen = new Gdk.Color(0, 0, 0);
            Gdk.Color c_selected = new Gdk.Color(255, 0, 0);

            this.ModifyBase(Gtk.StateType.Normal, c_hintergrund);
            Gdk.GC gc = this.Style.BaseGC(Gtk.StateType.Normal);
            this.GdkWindow.DrawRectangle(gc, true, 0, 0,
this.kasten_groesse.Width, this.kasten_groesse.Height);
            this.ModifyBase(Gtk.StateType.Normal, c_rahmen);
            if (Angeklickt) {
                this.ModifyBase(Gtk.StateType.Normal, c_selected);
            }
           
this.GdkWindow.DrawRectangle(this.Style.BaseGC(Gtk.StateType.Normal),
false, 0, 0, this.kasten_groesse.Width - 1, this.kasten_groesse.Height - 1);
           
this.GdkWindow.DrawRectangle(this.Style.BaseGC(Gtk.StateType.Normal),
false, 1, 1, this.kasten_groesse.Width - 3, this.kasten_groesse.Height - 3);
           
this.GdkWindow.DrawRectangle(this.Style.BaseGC(Gtk.StateType.Normal),
false, 2, 2, this.kasten_groesse.Width - 5, this.kasten_groesse.Height - 5);

            int w,h;
            layout.GetPixelSize(out w, out h);
           
this.GdkWindow.DrawLayout(this.Style.TextGC(StateType.Normal),
((kasten_groesse.Width / 2) - (w / 2)), ((kasten_groesse.Height / 2) -
(h / 2)), layout);
        }

i think the sourcecode of the exposed functions are correct. i will be
gratefully for any solution why the program using so much memory and cpu.
thanks
Thomas Zühlke

--------------030505010002020005000407
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hi *,<br>
i have written an <span>gtk</span>-sharp application in c# and
everything works fine. My main window is filled with a <span>Gtk</span>.Fixed
and on this, there will be other widgets placed.<br>
<br>
The problem: since the first widget is placed on the <span>Gtk</span>.Fixed
the program takes up to 90% of <span>cpu</span> usage and the used
memory is slowly growing up to infinity. During debugging i explored,
that there are 2 exposed functions, which are always called:<br>
the exposed function of the <span>gtk</span>.Fixed:<br>
<small><font face="Courier New, Courier, monospace">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public void
rahmen_ExposeEvent(object o, <span>Gtk</span>.<span>ExposeEventArgs</span>
<span>args</span>) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span>Gdk</span>.Color c_inaktiv = new <span>Gdk</span>.Color(0,
0, 0);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span>Gdk</span>.Color c_aktiv = new <span>Gdk</span>.Color(255,
0, 0);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span>foreach</span> (<span>Verbinder</span> verb in this.<span>verbindungen</span>)
{<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int x1, y1, x2, y2;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; verb.Von.<span>TranslateCoordinates</span>(this.bk, 0,
0, out x1, out y1);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; verb.Bis.<span>TranslateCoordinates</span>(this.bk, 0,
0, out x2, out y2);<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span>Gtk</span>.Requisition r1 = verb.Von.<span>SizeRequest</span>();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; x1 += r1.Width;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; y1 += ((verb.Von.kastenrahmen.kastenwidget.<span>SizeRequest</span>().Height/verb.Von.<span>kastenrahmen</span>.buttons_ausgabe.Count)/2);<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // <span>Linien</span>-<span>Ziel</span>-<span>Koordinaten</span>
<span>berechnen</span><br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; y2 += ((verb.Bis.kastenrahmen.kastenwidget.<span>SizeRequest</span>().Height/verb.Bis.<span>kastenrahmen</span>.buttons_eingabe.Count)/2);<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (verb.<span>VerbindungAktiv</span>) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this.<span>ModifyBase</span>(<span>Gtk</span>.<span>StateType</span>.Normal,
c_aktiv);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; } else {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this.<span>ModifyBase</span>(<span>Gtk</span>.<span>StateType</span>.Normal,
c_inaktiv);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this.<span>GdkWindow</span>.<span>DrawLine</span>(this.Style.<span>BaseGC</span>(<span>Gtk</span>.<span>StateType</span>.Normal),
x1, y1, x2, y2);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
</font></small>it runs checks a special <span>ArrayList</span> and
calculating coordinates of a view widgets ans draw lines between them.<br>
<br>
the exposed <span>funktion</span> of the widget on the <span>gtk</span>.fixed:<br>
<small><font face="Courier New, Courier, monospace">void
Kasten_ExposeEvent(object o, <span>Gtk</span>.<span>ExposeEventArgs</span>
<span>args</span>) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; kasten_groesse = this.<span>SizeRequest</span>();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span>Gdk</span>.Color c_hintergrund = new <span>Gdk</span>.Color(255,
255, 255);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span>Gdk</span>.Color c_rahmen = new <span>Gdk</span>.Color(0,
0, 0);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span>Gdk</span>.Color c_selected = new <span>Gdk</span>.Color(255,
0, 0);<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this.<span>ModifyBase</span>(<span>Gtk</span>.<span>StateType</span>.Normal,
c_hintergrund);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Gdk.GC gc = this.Style.BaseGC(<span>Gtk</span>.<span>StateType</span>.Normal);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this.GdkWindow.DrawRectangle(<span>gc</span>, true, 0, 0,
this.kasten_groesse.Width, this.kasten_groesse.Height);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this.ModifyBase(<span>Gtk</span>.<span>StateType</span>.Normal,
c_rahmen);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (<span>Angeklickt</span>) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this.ModifyBase(<span>Gtk</span>.<span>StateType</span>.Normal,
c_selected);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this.GdkWindow.DrawRectangle(this.Style.BaseGC(<span>Gtk</span>.<span>StateType</span>.Normal),
false, 0, 0, this.kasten_groesse.Width - 1, this.kasten_groesse.Height
- 1);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this.GdkWindow.DrawRectangle(this.Style.BaseGC(<span>Gtk</span>.<span>StateType</span>.Normal),
false, 1, 1, this.kasten_groesse.Width - 3, this.kasten_groesse.Height
- 3);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this.GdkWindow.DrawRectangle(this.Style.BaseGC(<span>Gtk</span>.<span>StateType</span>.Normal),
false, 2, 2, this.kasten_groesse.Width - 5, this.kasten_groesse.Height
- 5);<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int w,h;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; layout.<span>GetPixelSize</span>(out w, out h);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this.GdkWindow.DrawLayout(this.Style.TextGC(<span>StateType</span>.Normal),
((kasten_groesse.Width / 2) - (w / 2)), ((kasten_groesse.Height / 2) -
(h / 2)), layout);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</font></small><br>
<br>
i think the <span>sourcecode</span> of the exposed functions are
correct. i will be gratefully for any solution why the program using so
much memory and <span>cpu</span>.<br>
thanks<br>
Thomas <span>Z&uuml;hlke</span>
</body>
</html>

--------------030505010002020005000407--