-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
GH-35988: [C#] The C data interface implementation can leak on import #35996
Conversation
|
Hmm, so there are two (unrelated?) changes here. The first change (removing the The second change is IMHO the symptom of an implementation issue. arrow/cpp/src/arrow/c/bridge.cc Lines 1241 to 1261 in e920bed
Then, importing an array moves the user-supplied structure to the owned structure, like this: arrow/cpp/src/arrow/c/bridge.cc Lines 1285 to 1287 in e920bed
Therefore, the imported array structure does not depend on the lifetime of the user-supplied pointer. By the way, moving is cheap so you shouldn't fear any inefficiency here: arrow/cpp/src/arrow/c/helpers.h Lines 66 to 75 in e920bed
|
Ah, that's much nicer. You can tell I haven't been responsible for managing my own resources in a few years... . |
@@ -50,10 +50,6 @@ public static unsafe void ExportType(IArrowType datatype, CArrowSchema* schema) | |||
{ | |||
throw new ArgumentNullException(nameof(schema)); | |||
} | |||
if (schema->release != null) | |||
{ | |||
throw new ArgumentException("Cannot export schema to a struct that is already initialized."); |
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.
For what it's worth, it looks like this change fixes an issue I ran into using a C# exported stream from an older version of C++ Arrow, where the schema struct used when importing the stream was uninitialized: https://github.com/apache/arrow/blob/apache-arrow-10.0.1/cpp/src/arrow/c/bridge.cc#L1782 (this has since been fixed)
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 I understand correctly the basic premise is that, on import, we let CArrowArray
be in the garbage collector pool since it should be safe to destroy if we happen to lose all references to it (unlike an exported array which we assume will have external references)? That seems valid to me.
By embedding in the |
As far as I can understand, the code looks good now (but I'm not a C# developer). |
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.
LGTM. I'll merge this soon, if I don't hear any objections.
Conbench analyzed the 5 benchmark runs on commit There was 1 benchmark result indicating a performance regression:
The full Conbench report has more details. |
What changes are included in this PR?
To ensure proper cleanup, immediately copies the contents of the C structure into the imported class for arrays and streams.
Relaxes the requirement when exporting that the target structure appear uninitialized.
Are these changes tested?
Existing tests pass. We don't as yet seem to have a good way to test for memory leaks so no new tests have been added.
Are there any user-facing changes?
No.