Open athas opened 4 years ago
I have a few ideas on how to resolve this. One would be to use Arc
s 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.
The implementation of
FutharkContext
does not at any point callfuthark_context_free()
orfuthark_context_config_free()
. This means that the actual Futhark context object is not freed when theFutharkContext
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 forFutharkContext
, which should callfuthark_context_free()
andfuthark_context_config_free()
(in that order). If this is done, then the implementation of theCopy
andClone
traits should probably be removed.