Hi Nick,
I believe that a closure created with buildClosureX is not automatically
garbage collected because Poly/ML can't know how long a C function is
going to hold on to the callback for. Therefore, I suspect what's
happening is that Poly/ML can't garbage collect the list accum because
that is referenced by the callback function which is referenced by the
closure. This is desirable behaviour: accum is needed as long as there
is a chance that the callback can be called. If you clear out the
contents of accum explicitly then those contents can be garbage
collected but accum itself still won't be. That's my guess - I haven't
tested this hypothesis.
Phil
On 14/03/19 14:01, Kostirya wrote:
Hello.
I found memory leak when FFI callback and ref value.
I checked Poly/ML 5.8 and 5.7.
Simple code for reproduce the memory leak is attached.
To prevent the memory leak I clean ref value (see comment in example).
But It must do the garbage collector, is it? At least MLton have not
this problem.
Result of run of example code:
Without clean ref value (The memory leak is)
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
nick 19855 91,8 9,7 305016 289452 6 S+ 16:53 0:17,94 poly --script cb-po
With clean ref value
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
nick 19862 65,3 0,6 32632 17476 6 S+ 16:54 0:10,77 poly --script cb-poly
Best, Nick.
_______________________________________________
polyml mailing list
polyml@inf.ed.ac.uk
http://lists.inf.ed.ac.uk/mailman/listinfo/polyml
_______________________________________________
polyml mailing list
polyml@inf.ed.ac.uk
http://lists.inf.ed.ac.uk/mailman/listinfo/polyml