[Gtk-sharp-list] gtk-dotnet performance

Crucius, Wesley WCrucius at sandc.com
Wed Mar 1 13:00:49 EST 2006


Guys,

I have a [related?] MASSIVE memory leak (60MB for 1024x768 pixbuf) when
I do the following:

  // INITIALLY load up the svg (XML) file for the one-line graphics
(into an XmlDoc) 
  xmlDoc = new System.Xml.XmlDocument();
  xmlDoc.Load("prettypicture.svg");
  // now we have an XML document that we can manipulate and
[re-]render...

  < ... much code deleted here ... >

  // PERIODICALLY [re-]render the SVG into the appropriate image Widget

  // (This snippet executes when the SVG xmlDoc has been modified by
other code)
  System.IO.MemoryStream streamSVG = new System.IO.MemoryStream();
  xmlDoc.Save(streamSVG);  // put the XML doc in a Stream
  streamSVG.Position = 0;  // reset the stream once written, this is
IMPORTANT!               
  imgWdgt.Pixbuf.Unref();  // this DRAMATICALLY slows the leak, but not
good enough
  imgWdgt.Pixbuf = null;   // this was just a guess, it has no effect...
  imgWdgt.Pixbuf = new Gdk.Pixbuf(streamSVG);  // probably actually uses
Rsvg?
  //System.GC.Collect();     // this was just a guess, it has no
effect...

I see a similar memory leak when directly the Rsvg library, so I'm
guessing that the problem is actually there (or in one of Rsvg's
dependancies, maybe libXML?), since I'm betting that Gtk.Pixbuf
implements it's SVG rendering capability by using rsgv?  Here's the Rsvg
version of the "bitmap refresh":

  imgWdgt.Pixbuf.Unref();  // this DRAMATICALLY slows the leak, but not
good enough!
  imgWdgt.Pixbuf = null;   // this was just a guess, it has no effect...
  imgWdgt.Pixbuf = Rsvg.Pixbuf.LoadFromStream(streamSVG);       
  //System.GC.Collect();     // this was just a guess, it has no
effect...

I would really appreciate some light being shed on this too, as
presently I am shelling out to command-line rsvg to render a .png to
disk and then loading that, but that is not a work-able long term
solution for me (I will wear out my CF-only-based storage media!)...

Thanks,
Wes

-----Original Message-----
From: gtk-sharp-list-bounces at lists.ximian.com
[mailto:gtk-sharp-list-bounces at lists.ximian.com] On Behalf Of Scott
Ellington
Sent: Wednesday, March 01, 2006 10:26 AM
To: Jonathan Resnick
Cc: gtk-sharp-list at lists.ximian.com
Subject: Re: [Gtk-sharp-list] gtk-dotnet performance

Hi Jonathan,

I have just tried your test app and I am not seeing times near 1 second:

Frame 197: 116 msec
Frame 198: 148 msec
Frame 199: 106 msec

As for your first option, there is definitely a memory leak ocurring.  I
could not pinpoint where that is, but I believe you are incorrect in
thinking that it is the Gtk.DotNet.Graphics.FromDrawable (window) in the
Expose Event.  I do that exact thing with no such memory leak:

http://forge.novell.com/modules/xfmod/svn/svnbrowse.php?uri=filedetails.
php%3Frepname%3Dappomattox%26path%3D%252Ftrunk%252FAppomattox%252Fsrc%25
2FAppomattox.Gui.Components%252FMapCanvas.cs

Scott

On Tue, 2006-02-28 at 22:07 -0500, Jonathan Resnick wrote:
> I am trying to port an open-source medical imaging application from 
> .NET to Mono so that it can run on Linux. A large part of the codebase

> is based on the System.Drawing library - therefore I am trying to use 
> the gtk-dotnet bridge so that GTK can be used as a front end. However,

> I'm having a hard time getting decent performance, and as far as I can

> tell, the problems seem to stem from the gtk-dotnet component.
> 
> I've attached a sample application that just tries to flip two 
> System.Drawing.Bitmaps to a Gtk.DrawingArea, alternating them, in a 
> tight loop. It measures the time taken for each flip and prints it to
the console.
> 
> On Linux, I observe the following behaviour:
> 
> 1. My first approach was to try drawing directly to the screen 
> (_drawDirect = true in the OnExposeEvent handler). The performance is 
> good for roughly the first 100 or so loop iterations, but then it 
> quickly degrades. It seems as though the system starts to run out of 
> memory, which seems to be caused by creating a Graphics object using 
> Gtk.DotNet.Graphics.FromDrawable inside the OnExposeEvent handler.
> 
> 2. My second approach was to try drawing to an intermediate Pixmap 
> (_drawDirect = false in the OnExposeEvent handler), so as to avoid 
> having to create a Graphics object each time. In this case, the 
> performance is constant over the entire duration of the loop. However,

> the performance is pretty bad, taking roughly 1 second per flip, which

> is not acceptable for our purposes (and I'm running it on a reasonably
powerful laptop machine).
> 
> If someone with a solid understanding of Gtk/Gdk could look at my 
> sample code and point out to me where I'm going wrong, it would be a 
> huge help in getting this application running on Linux.
> 
> Thanks,
> 
> Jonathan
> 
> _______________________________________________
> Gtk-sharp-list maillist  -  Gtk-sharp-list at lists.ximian.com 
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list

_______________________________________________
Gtk-sharp-list maillist  -  Gtk-sharp-list at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list




More information about the Gtk-sharp-list mailing list