Thread: [Java-gnome-developer] Pixbuf
Brought to you by:
afcowie
From: Douglaz <do...@gm...> - 2010-08-26 17:54:42
|
Hello everyone! I'm writing a small application which is collecting the image from a few ip cameras and showing them in a grid. In order to do so, I have a few threads collecting the bytes, creating new Pixbuf object with those bytes, and updating a DataColumnPixbuf. I noticed an increase of the memmory usage as time goes by. Should I by using some method in order to free those unused Pixbuf objects? Or is there a way to update these existing objects? Best regards, Douglas ps.: In the following tiny test you can see the memmory increase (checking the system resources): package camera; import javax.swing.JOptionPane; import org.gnome.gdk.Pixbuf; import org.gnome.gtk.Gtk; public class Main { public Main() { super(); Loader loader = new Loader(); loader.start(); JOptionPane.showMessageDialog(null, "Press ok to exit the program"); } public static void main(String[] arsg) { Gtk.init(new String[] {}); new Main(); System.exit(0); } protected class Loader extends Thread { public void run() { while (true) { try { Pixbuf p1 = new Pixbuf("camera.jpg"); Pixbuf p2 = new Pixbuf("camera.jpg"); Pixbuf p3 = new Pixbuf("camera.jpg"); sleep(200); } catch (Exception e) { e.printStackTrace(); } } } } } |
From: Andrew C. <an...@op...> - 2010-08-27 04:23:20
|
On Thu, 2010-08-26 at 14:54 -0300, Douglaz wrote: > import javax.swing.JOptionPane; > import org.gnome.gdk.Pixbuf; You're trying to mix java-gnome and Swing. That's not going to work. [I could go on at great length about why mixing toolkits is a bad idea, but what's relevant here, even if it is briefly "working" for you, is that no one can help you diagnose things like memory problems when two entirely different mechanisms for talking to the native graphics libraries are at play]. AfC Sydney |
From: Douglaz <do...@gm...> - 2010-08-27 13:29:19
|
Hey AfC! Thanks for taking some time to check my code. You are right, the sample I attached was not properly written. But the application where I first noticed the issue uses java-gnome only. So what I did was change the sample code to use java-gnome only, and I still can see the mem going up. Any inputs would be very appreciated! Best regards, Douglas Sample code: import org.gnome.gdk.Event; import org.gnome.gdk.Pixbuf; import org.gnome.gtk.Gtk; import org.gnome.gtk.Widget; import org.gnome.gtk.Window; public class Main { public static void main(String[] arsg) { Gtk.init(new String[] {}); new Main(); } public Main() { super(); Window window = new Window(); window.connect(new Window.DeleteEvent() { public boolean onDeleteEvent(Widget widget, Event event) { Gtk.mainQuit(); System.exit(0); return false; } }); window.setTitle("Close to end"); window.show(); for (int i = 0; i < 10; i++) { new Loader().start(); } Gtk.main(); } protected class Loader extends Thread { @Override public void run() { while (true) { try { Pixbuf pixbuf = new Pixbuf("camera.jpg"); System.out.println(pixbuf); // Would set this Pixbuf in an Image to be shown on the screen; sleep(200); } catch (Exception e) { e.printStackTrace(); } } } } } 2010/8/27 Andrew Cowie <an...@op...> > On Thu, 2010-08-26 at 14:54 -0300, Douglaz wrote: > > import javax.swing.JOptionPane; > > import org.gnome.gdk.Pixbuf; > > You're trying to mix java-gnome and Swing. That's not going to work. > > [I could go on at great length about why mixing toolkits is a bad idea, > but what's relevant here, even if it is briefly "working" for you, is > that no one can help you diagnose things like memory problems when two > entirely different mechanisms for talking to the native graphics > libraries are at play]. > > AfC > Sydney > > > > ------------------------------------------------------------------------------ > Sell apps to millions through the Intel(R) Atom(Tm) Developer Program > Be part of this innovative community and reach millions of netbook users > worldwide. Take advantage of special opportunities to increase revenue and > speed time-to-market. Join now, and jumpstart your future. > http://p.sf.net/sfu/intel-atom-d2d > _______________________________________________ > java-gnome-developer mailing list > jav...@li... > https://lists.sourceforge.net/lists/listinfo/java-gnome-developer > > |
From: Andrew C. <an...@op...> - 2010-08-29 03:00:23
|
On Fri, 2010-08-27 at 10:29 -0300, Douglaz wrote: > So what I did was change the sample code to use java-gnome only, > and I still can see the mem going up. Without having looked at your code to see if you're leaking anything, in general we do have a broader issue. I'm not especially concerned about it, but it's on the list of things to think about. Have a read of the thread starting at http://article.gmane.org/gmane.comp.gnome.bindings.java.devel/1432 It may be you're running afoul of that aspect of Java. AfC Sydney |