> The function works fine, but after some time it fails Are you using default refc GC or new --gc:arc?
I assume default refc. In that case I would assume that there is something wrong in your bindings, so when the GC starts for the first time it fails. You may call GC_Fullcollect() early, then the bug may occur earlier. And you can try too compile with --gc:arc -d:useMalloc, then you have a more deterministic GC and the error may come earlier. In this case you can also try running your app by valgrind, valgrind may tell you details. You can also play with --gc:none, maybe then your app runs longer, until all memory is consumed. That are the first steps I would try...
