elixir-explorer / adbc

Apache Arrow ADBC bindings for Elixir
https://arrow.apache.org/adbc/
Apache License 2.0
50 stars 16 forks source link

WIP: automated cleanup of NifRes using RAII #7

Closed Qqwy closed 1 year ago

Qqwy commented 1 year ago

The idea behind this PR is to manage the setup and cleanup of NifRes<T>'s automatically, using C++'s builtin scope-based construction/destruction functionality (AKA RAII).

This allows us to remove all manual calls to enif_release_resource in the code, making it less error-prone to use NifRes/harder to accidentally leak memory.


This PR is a work-in-progress. Things that need to happen before merging:

cocoa-xu commented 1 year ago

Hi @Qqwy, thank you very much for the PR!

I'm still thinking whether there is a nicer approach rather than using unique_ptr with a custom deleted.

Yes, I think that's quite a good idea!

btw the error message in the Linux CI workflow is probably because we didn't include <memory> (although I'm not 100% sure about it... haven't tried to compile this on my Linux machine).