GH-765: Do not close/free imported BaseStruct objects#766
GH-765: Do not close/free imported BaseStruct objects#766lidavidm merged 1 commit intoapache:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
|
#763 (comment) suggests adding new or overloaded methods that do not call close instead of introducing a breaking change. Is there any preference wrt naming these? |
|
Perhaps by analogy with the base library, |
|
Just FYI, I'm experimenting a bit, and neither the
The overload of |
|
Hmm. A single boolean flag seems fine for Alternatively: add a constructor boolean parameter for |
|
I've pushed a second attempt that introduces overloaded import methods with a boolean argument. I've moved all the close calls to the Data class for clarity. |
| ArrowArrayStreamReader reader = new ArrowArrayStreamReader(allocator, stream); | ||
| if (closeImportedStructs) { | ||
| stream.close(); | ||
| } | ||
| return reader; |
There was a problem hiding this comment.
(1) the indentation seems off?
(2) should we put this in a try-with-resources to at least fix the edge case noted (failure to free in case of exception)?
There was a problem hiding this comment.
Indentation fixed has been corrected.
Regarding the stream#close call, I went for maintaining the exact current behavior. The ArrowArrayStreamReader constructor did not call close in a finally block. Let me know if you would prefer to change this.
|
Looks reasonable to me, thanks. |
|
checkstyle is still unhappy: |
|
Additionally, could we add a small unit test if possible? Otherwise LGTM |
|
Checkstyle issues should be fixed. I'll add some unit tests next. |
18b3aff to
6c093db
Compare
…orted BaseStruct objects
|
I've added a couple of tests. |
What's Changed
This PR removes the direct and indirect calls to
BaseStruct#closefromorg.apache.arrow.c.Data. By not eagerly closing/freeing these objects callers can reuse instances multiple times.This contains breaking changes.: a quick check in, for instance,org.apache.arrow.c.StreamTestshows that a lot of existing code is already written using try-with-resources. This change will not have any impact there. Code that does not use a try-with-resources or try-finally-close pattern and instead counts onDatato callclosewill report memory leaks after this change.The second version of this PR removes the breaking change.
Closes #765.