Ability to unload an ffi-lib?

34 views
Skip to first unread message

Chris P

unread,
Sep 5, 2019, 10:59:20 PM9/5/19
to Racket Users
Is it possible to unload an ffi-lib? I'm doing development on Windows where loading a DLL locks it and prevents the DLL from being recompiled.

There was another post on this, but it was about 7 years old, so I thought I would see if anything has changed.

Thanks,
Chris

Matthew Flatt

unread,
Sep 6, 2019, 9:09:39 AM9/6/19
to Chris P, Racket Users
There's still no mechanism to unload a DLL.

For a long time, it wasn't practical to try to unload a DLL, because
the finalization mechanisms were too asynchronous --- making it
difficult to detect the point where the DLL would no longer be
referenced and could be unloaded safely. But support for
custodian-managed finalization has improved to the point where this
problem is worth revisiting, and I'll take another look soon.
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/0645cc02-20d2-493c-a04f-b872ca19
> f3b3%40googlegroups.com.

Chris Pettitt

unread,
Sep 6, 2019, 6:23:18 PM9/6/19
to Matthew Flatt, Racket Users
That sounds great! I would love to take advantage of it when it becomes available.

Thanks,
Chris

On Fri, Sep 6, 2019 at 7:09 AM Matthew Flatt <mfl...@cs.utah.edu> wrote:
There's still no mechanism to unload a DLL.

For a long time, it wasn't practical to try to unload a DLL, because
the finalization mechanisms were too asynchronous --- making it
difficult to detect the point where the DLL would no longer be
referenced and could be unloaded safely. But support for
custodian-managed finalization has improved to the point where this
problem is worth revisiting, and I'll take another look soon.

At Thu, 5 Sep 2019 19:59:19 -0700 (PDT), Chris P wrote:

Matthew Flatt

unread,
Sep 6, 2019, 8:17:39 PM9/6/19
to Chris Pettitt, Racket Users
The next snapshot build (available in 18 hours or so at
pre.racket-lang.org) includes a `#:custodian` optional argument to
`ffi-lib`. Probably you want `#:custodian (current-custodian)`, which
will unload the foreign library for a program run in DrRacket in
reaction to "Kill" or "Run".

Beware that `#:custodian (current-custodian)` will not interact nicely
with GC-based finalization via `register-finalizer` or
`ffi/unsafe/alloc`. If you have values to finalize,
`register-finalizer-and-custodian-shutdown` could be the way to go, but
beware that `register-finalizer-and-custodian-shutdown` provides no
ordering guarantee (unlike the `ffi/unsafe/alloc` interface). In other
words, there's still no simple answer to all problems, just a new
answer for some simple problems.
> https://groups.google.com/d/msgid/racket-users/CAPsvE6L1Hw%2BeGjMJZ3MDzOJxw6WFT
> Ff_%3DmBRn9s6PxXJxZc3GQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages