Erk- / genfut

Generate bindings for Futhark
ISC License
37 stars 10 forks source link

Missing deallocation of context object #15

Open athas opened 4 years ago

athas commented 4 years ago

The implementation of FutharkContext does not at any point call futhark_context_free() or futhark_context_config_free(). This means that the actual Futhark context object is not freed when the FutharkContext Rust object is destroyed. GPU resources may thus be leaked until the process ends entirely and they are reclaimed by the operating system.

I recommend adding an implementation of the Drop trait for FutharkContext, which should call futhark_context_free() and futhark_context_config_free() (in that order). If this is done, then the implementation of the Copy and Clone traits should probably be removed.

Erk- commented 3 years ago

I have a few ideas on how to resolve this. One would be to use Arcs to refer to the context from other objects and first free the Context when there are no objects that refer to it.

Another way would be that onjects have Weak pointers to the Context which have a strong Arc this way the context can get freed when there are still objects alive. We could then have a new error that can happen when the context have been freed.

And finally there is also the original idea of using borrowed references in objects, which will work, but may not be nice to work with.