Fallible Drop Method

What is the best practice for implementing a Drop method that can fail?

The reason I ask is because CUDA can return a failure code from device-memory-deallocation functions and other things that I'd like to call in Drop::drop. The compromise that I've gone with for RustaCUDA is to panic if Drop::drop is unable to drop a value, but to provide a separate Foo::drop function that returns the error and the un-dropped object instead, if deallocation fails.

Is there a better approach known? I suppose it could just leak the allocated memory, but that seems undesirable.

Well, things such as File just ignore failures to close the file. It's not clear that there is much you can do about the failure, and triggering a panic in the destructor is prone to panics during panics, which immediately abort the process.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.