memory and containers
"Jacques Le Normand" <[email protected]>
| Newsgroups | gmane.comp.lang.ocaml.lib.gtk |
|---|---|
| Message-ID | <[email protected]> |
Hello lablgtk,
I'm currently writing an application which displays a mix of text and
GEdit.entry widgets in a GText.view . It also changes what's displayed
several times a second, forcing me to clear the buffer and insert new
GEdit.entry. It seems that placing and removing many GEdit.entry from a
GText.view starts taking up a lot of memory rather quickly. How can I fix
this? I've written an example program that creates a window and that adds
100 GEdit.entry every time you press a key. Pressing a key many times shows
this application taking upwards of 100 megabytes (and slowing down
considerably). How can I fix this?
here's the program:
let repeat n f =
let rec rep i =
if i = n then () else (f () ; rep (i+1))
in
rep 0
let clearTextBuffer (tb:GText.buffer) =
let a = tb#start_iter in
let b = tb#end_iter in
tb#delete a b
let _ =
let source_window = GWindow.window ~width:100 ~height:100 () in
let buffer = GText.buffer () in
let view = GText.view ~buffer:buffer ~packing:source_window#add () in
let fill_view () =
let add_entry () =
view#add_child_at_anchor (GEdit.entry () :> GObj.widget)
(buffer#create_child_anchor (buffer#end_iter));
in
clearTextBuffer buffer;
repeat 100 add_entry;
in
ignore
(view#event#connect#key_press
~callback:(fun _ -> fill_view ();false));
source_window#show ();
GMain.Main.main ()
_______________________________________________
Lablgtk mailing list
[email protected]
http://yquem.inria.fr/cgi-bin/mailman/listinfo/lablgtk