English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] Garbage Collect Problem in Library
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-12-27 (21:47)
From: Warp <warplayer@f...>
Subject: [Caml-list] Garbage Collect Problem in Library
I got some trouble with the garbage collector.
I manage to make callbacks from my dynamic linked library, passing it
the callbackN_exn C API function address when it loads.
Now i'm doing theses things :

value caml_createwindow( value callback ) {
    HWND handle_of_window = CreateWindow()
    value v = alloc( 4 , MY_TAG ); // alloc is also a reference to
interpreter alloc function
    Store_field( v , 0, handle_of_window ); // here we also got a "modify"
    Store_field( v , 1, callback_value );
    SetWindowData( handle_of_window, v );
    return v;

So , the user got the ' v ' caml value which mainly contains the real handle
of the window and the callback.
And the window itself can obtain ' v ' from handle by calling
etWindowData( handle_of_window );

in the window proc I'm getting that ' v ' data like that and then I'm
calling caml callback.
All it's fine, but after 10 seconds, the garbage collector collects my ' v '
( I can see that the Tag_val is set to Zero ).

How can i prevent that ?
Shall I use CAMLparamX and other garbage-living-in-harmony-stuff ?
Theses macros are using local_root so do I have to make my library ask the
current local_root from the interpreter ?

Thanks for any help !


Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr