Re: Leaking pixmaps
Jon Harrop <[email protected]>
| Newsgroups | gmane.comp.lang.ocaml.lib.gtk |
|---|---|
| Organization | Flying Frog Consultancy Ltd. |
| Message-ID | <[email protected]> |
On Wednesday 09 January 2008 10:53:51 Jon Harrop wrote:
> Has anyone found a bug where using pixmaps causes a memory leak resulting
> in X consuming all memory and dying?
>
> I just ditched pixmaps in favour of direct rendering which fixed the
> problem and the symptom deterred me from investigating...
Spoke too soon. The problem also appears without pixmaps.
The following program tries to incrementally render randomly colored dots but,
instead, just overloads X and kills my entire window system when I try to
resize the window:
(*
ocamlopt -dtypes bigarray.cmxa -I +lablgtk2 lablgtk.cmxa gtkInit.cmx
gtktest.ml -o gtktest
*)
let window = GWindow.window ~width:512 ~height:512 ~title:"Ray tracer" ()
let vbox = GPack.vbox ~packing:window#add ()
let drawing_area = GMisc.drawing_area ~packing:vbox#add ()
let drawable =
drawing_area#misc#realize ();
new GDraw.drawable drawing_area#misc#window
let key_press key =
if GdkEvent.Key.keyval key = GdkKeysyms._Escape then
GMain.Main.quit();
false
let paint ev =
let rect = GdkEvent.Expose.area ev in
let x = Gdk.Rectangle.x rect and y = Gdk.Rectangle.y rect in
let w = Gdk.Rectangle.width rect and h = Gdk.Rectangle.height rect in
let width, height = drawable#size in
Printf.printf "(%d, %d) + (%d, %d): %d / %d\n%!" x y w h y height;
for x = x to x + w - 1 do
drawable#set_foreground (`RGB(Random.int 65536, Random.int 65536,
Random.int 65536));
drawable#point ~x ~y;
done;
drawing_area#misc#draw(Some(Gdk.Rectangle.create x (y + 1) width (height -
1)));
true
let () =
ignore(window#event#connect#key_press ~callback:key_press);
ignore(window#connect#destroy ~callback:GMain.Main.quit);
ignore(drawing_area#event#connect#expose ~callback:paint);
window#show();
GMain.Main.main ()
Looks like the call to "drawable#set_foreground" is leaking resources like a
sieve.
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/products/?e