-
Notifications
You must be signed in to change notification settings - Fork 173
feat(r): Reference count child objects #1334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(r): Reference count child objects #1334
Conversation
…y stream (#333) Uncovered when investigating apache/arrow-adbc#1348 and apache/arrow-adbc#1334 . Before, the release callback was getting called by the garbage collector (so no memory leak was reported); however, the order of the array stream finalizer and the user-supplied R finalizer was non-deterministic based on when the garbage collector ran.
…y stream (apache#333) Uncovered when investigating apache/arrow-adbc#1348 and apache/arrow-adbc#1334 . Before, the release callback was getting called by the garbage collector (so no memory leak was reported); however, the order of the array stream finalizer and the user-supplied R finalizer was non-deterministic based on when the garbage collector ran.
| self_contained_finalizer <- function() { | ||
| try(adbc_release_non_null(x)) | ||
| try({ | ||
| parent$.child_count <- parent$.child_count - 1L |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this and other code be using adbc_update_parent_child_count() or a variant under the hood?
|
|
||
| #include <utility> | ||
|
|
||
| #include <adbc.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this include is added here, should we remove it from some source files?
krlmlr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only skimmed over the code, we'll see how behavior improves when we use it.
This PR adds a
.child_countfor all database, connection, and statement objects to ensure that we do not call the C-level release callback while a child object is available.Since very early commits, we had set
R_ExternalPtrProtected()to the parent object, which meant that if you never calledadbc_XXX_release(), R would correctly sort out the object dependencies and call the release callbacks in the correct order.One major exception to that was the returned
ArrowArrayStreamwrappers, for which there was no mechanism to add a dependent SEXP until I added it (in nanoarrow 0.2, I think); however, it wasn't actually used for anything except for the stream returned byread_adbc().@nbenn / @krlmlr you are probably the best candidates to give this a review/ensure that it fixes or makes it easier to debug the issues you have been having in adbi! Note that apache/arrow-nanoarrow#333 may have been the primary culprit (I will push that out to CRAN ASAP as a tweak release).
Closes apache/arrow-nanoarrow#323 , #1128 . Perhaps related: #1348 .
I triggered some extended checks as well (as they include valgrind): https://github.com/paleolimbot/arrow-adbc/actions/runs/7133874110