On 29/01/12 15:57, David Matthews wrote:
On 27/01/2012 20:15, Phil Clayton wrote:
Thinking about explicitly deleting callbacks led me to ask whether each
ML function passed as a callback has its callback reused on subsequent
calls. If reuse occurs, the number of call sites in the source code
would bound memory usage.
I'm guessing that these callback objects are actually wrappers to invoke
compiled ML code and that there is only one instance of the compiled ML,
so there would be no problem having only one instance of the callback
object.
It would be nice if they could be reused but currently they aren't. I
had a look at the code and did some experiments but the problem is that
there is quite a lot of ML wrapping going on. That means that the RTS
can't detect that the same function has been passed a second time. After
the wrapping has been applied the closure that gets passed into the RTS
is always different even if the same ML function was used further up.
I sometimes think the whole FFI system should be redesigned to remove
some of the layers.
Thanks for investigating. It looks like every callback is leaking
something like 0x38 bytes of memory which isn't an issue in the short
term while I am only developing prototype GTK applications. (An
application would need to run for days, if not weeks, for this to cause
problems.)
I suspect that it would be possible to call an explicit delete from C on
the callback pointer when no longer required. Is that the sort of
mechanism you envisaged for deleting callbacks? However, I am happy if
you want to hold off any solution as the issue is not a show-stopper.
Phil
_______________________________________________
polyml mailing list
[email protected]
http://lists.inf.ed.ac.uk/mailman/listinfo/polyml