Hi all,
please correct me if I'm wrong, I haven't looked at this since one or two
years, but I am pretty
sure about the reason for the leak in the test code. As it never enters gtk
main loop, our reference
to the underlying GdkPixbuf object is never released. That is because we
release it in a g_idle
function that is only executed inside the gtk main loop. So just doing:
while (Gtk.eventsPending()) {
Gtk.mainIterationDo(false);
}
after Pixbuf creation will solve the memory leak. I've tested it and it works.
***
Details hereafter, you can skip this unless you understand our memory
management system. Please
note I may be forgetting something, it was a long time ago since the last look
I took at this stuff.
****
So, let's start. When the Pixbuf is created, a native gdk function is invoked,
which in turn returns a
GObject WE OWN. When the Proxy is created, java side, in org.gnome.glib.Object
we invoke
GObject.addToggleRef. This adds a new gtk ref (toggle ref) together with a
strong ref in java. At this
moment, we hold two native ref to the GdkPixbuf (the original plus the toggle)
and two java refs
(the one corresponding to the pb ref in our code plus the internal one). All
this happens in bindings_java_memory_ref.
Of course, our original ref is no longer needed (we already hold the toggle
ref) so we dispose it.
However, we do that in a g_idle function, to avoid the toggle ref for being
"toggled" unnecessarily
(ok, unnecessarily in most cases, where the object is right next added to a
container). In this case, as
the main loop was never executed, the original ref was never removed.
Back in our code, after one loop step, the pb var is out of scope. However, we
still keep the additional java
ref, so the Pixbuf object never goes out of scope java side, so the GC never
collects it.
Note that this extra ref is released (actually turned weak) after the toggle
ref is the last one, which happens
when both the main loop is executed (and thus original ref is removed), and pb
goes out of scope.
I hope I have explained it properly, just comment here if you need more details.
Cheers
Vreixo
PS: AfC, I think I need a chat with you this week about builder related stuff.
I hope we both have time for that.
----- Mensagem original -----
De: William Temperley <[email protected]>
Para: java-gnome-developer <[email protected]>
Cc:
Enviadas: Quarta-feira, 19 de Outubro de 2011 19:01
Assunto: [Java-gnome-developer] Pixbuf memory leak
Hi all,
I've come across a memory leak with Pixbuf - whenever I construct one,
lots of memory is leaked. The test below leaks ~200MB when loading a
6kb image 10,000 times. Commenting out the Pixbuf construction leads
to steady memory use.
This memory usage isn't reported by the JVM. I've come across this
behaviour with 4.0.19 and 4.1.1.
Whilst I'd love a proper solution to this, I wonder if anyone has a
quick and dirty workaround for freeing up this memory? I'm doing a
production run of approximately 6000 maps for a website, which grinds
to a halt after 100 or so maps, using all 8GB of RAM.
Thanks
Will Temperley
@Test
public void itLeaks() throws IOException {
Gtk.init(null);
for (int i = 0; i < 10000; i++) {
System.out.println(i);
BufferedImage b = ImageIO.read(new File("/tmp/x.png"));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ImageIO.write(b, "PNG", bos);
byte[] arr = bos.toByteArray();
//comment out and memory usage remains steady
Pixbuf pb = new Pixbuf(arr);
}
}
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2d-oct
_______________________________________________
java-gnome-developer mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/java-gnome-developer
------------------------------------------------------------------------------
The demand for IT networking professionals continues to grow, and the
demand for specialized networking skills is growing even more rapidly.
Take a complimentary Learning@Cisco Self-Assessment and learn
about Cisco certifications, training, and career opportunities.
http://p.sf.net/sfu/cisco-dev2dev
_______________________________________________
java-gnome-developer mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/java-gnome-developer