[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"> public void
rahmen_ExposeEvent(object o, <span>Gtk</span>.<span>ExposeEventArgs</span>
<span>args</span>) {<br>
<span>Gdk</span>.Color c_inaktiv = new <span>Gdk</span>.Color(0,
0, 0);<br>
<span>Gdk</span>.Color c_aktiv = new <span>Gdk</span>.Color(255,
0, 0);<br>
<span>foreach</span> (<span>Verbinder</span> verb in this.<span>verbindungen</span>)
{<br>
int x1, y1, x2, y2;<br>
verb.Von.<span>TranslateCoordinates</span>(this.bk, 0,
0, out x1, out y1);<br>
verb.Bis.<span>TranslateCoordinates</span>(this.bk, 0,
0, out x2, out y2);<br>
<br>
<span>Gtk</span>.Requisition r1 = verb.Von.<span>SizeRequest</span>();<br>
x1 += r1.Width;<br>
y1 += ((verb.Von.kastenrahmen.kastenwidget.<span>SizeRequest</span>().Height/verb.Von.<span>kastenrahmen</span>.buttons_ausgabe.Count)/2);<br>
<br>
// <span>Linien</span>-<span>Ziel</span>-<span>Koordinaten</span>
<span>berechnen</span><br>
y2 += ((verb.Bis.kastenrahmen.kastenwidget.<span>SizeRequest</span>().Height/verb.Bis.<span>kastenrahmen</span>.buttons_eingabe.Count)/2);<br>
<br>
if (verb.<span>VerbindungAktiv</span>) {<br>
this.<span>ModifyBase</span>(<span>Gtk</span>.<span>StateType</span>.Normal,
c_aktiv);<br>
} else {<br>
this.<span>ModifyBase</span>(<span>Gtk</span>.<span>StateType</span>.Normal,
c_inaktiv);<br>
}<br>
this.<span>GdkWindow</span>.<span>DrawLine</span>(this.Style.<span>BaseGC</span>(<span>Gtk</span>.<span>StateType</span>.Normal),
x1, y1, x2, y2);<br>
}<br>
}<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>
kasten_groesse = this.<span>SizeRequest</span>();<br>
<span>Gdk</span>.Color c_hintergrund = new <span>Gdk</span>.Color(255,
255, 255);<br>
<span>Gdk</span>.Color c_rahmen = new <span>Gdk</span>.Color(0,
0, 0);<br>
<span>Gdk</span>.Color c_selected = new <span>Gdk</span>.Color(255,
0, 0);<br>
<br>
this.<span>ModifyBase</span>(<span>Gtk</span>.<span>StateType</span>.Normal,
c_hintergrund);<br>
Gdk.GC gc = this.Style.BaseGC(<span>Gtk</span>.<span>StateType</span>.Normal);<br>
this.GdkWindow.DrawRectangle(<span>gc</span>, true, 0, 0,
this.kasten_groesse.Width, this.kasten_groesse.Height);<br>
this.ModifyBase(<span>Gtk</span>.<span>StateType</span>.Normal,
c_rahmen);<br>
if (<span>Angeklickt</span>) {<br>
this.ModifyBase(<span>Gtk</span>.<span>StateType</span>.Normal,
c_selected);<br>
}<br>
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>
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>
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>
int w,h;<br>
layout.<span>GetPixelSize</span>(out w, out h);<br>
this.GdkWindow.DrawLayout(this.Style.TextGC(<span>StateType</span>.Normal),
((kasten_groesse.Width / 2) - (w / 2)), ((kasten_groesse.Height / 2) -
(h / 2)), layout);<br>
}</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ühlke</span>
</body>
</html>
--------------030505010002020005000407--