Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tianlh
LightGBM-DCU
Commits
8b61a150
Unverified
Commit
8b61a150
authored
Feb 22, 2024
by
Oliver Borchert
Committed by
GitHub
Feb 22, 2024
Browse files
[c++] Fix memory leak in Arrow table implementation (#6314)
Co-authored-by:
James Lamb
<
jaylamb20@gmail.com
>
parent
894066db
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
1 deletion
+20
-1
include/LightGBM/arrow.h
include/LightGBM/arrow.h
+20
-1
No files found.
include/LightGBM/arrow.h
View file @
8b61a150
...
...
@@ -207,6 +207,9 @@ class ArrowChunkedArray {
*/
class
ArrowTable
{
std
::
vector
<
ArrowChunkedArray
>
columns_
;
const
int64_t
n_chunks_
;
const
ArrowArray
*
chunks_ptr_
;
const
ArrowSchema
*
schema_ptr_
;
public:
/**
...
...
@@ -216,7 +219,8 @@ class ArrowTable {
* @param chunks A C-style array containing the chunks.
* @param schema The schema for all chunks.
*/
inline
ArrowTable
(
int64_t
n_chunks
,
const
ArrowArray
*
chunks
,
const
ArrowSchema
*
schema
)
{
inline
ArrowTable
(
int64_t
n_chunks
,
const
ArrowArray
*
chunks
,
const
ArrowSchema
*
schema
)
:
n_chunks_
(
n_chunks
),
chunks_ptr_
(
chunks
),
schema_ptr_
(
schema
)
{
columns_
.
reserve
(
schema
->
n_children
);
for
(
int64_t
j
=
0
;
j
<
schema
->
n_children
;
++
j
)
{
std
::
vector
<
const
ArrowArray
*>
children_chunks
;
...
...
@@ -229,6 +233,21 @@ class ArrowTable {
}
}
~
ArrowTable
()
{
// As consumer of the Arrow array, the Arrow table must release all Arrow arrays it receives
// as well as the schema. As per the specification, children arrays are released by the
// producer. See: https://arrow.apache.org/docs/format/CDataInterface.html#release-callback-semantics-for-consumers
for
(
int64_t
i
=
0
;
i
<
n_chunks_
;
++
i
)
{
auto
chunk
=
&
chunks_ptr_
[
i
];
if
(
chunk
->
release
)
{
chunk
->
release
(
const_cast
<
ArrowArray
*>
(
chunk
));
}
}
if
(
schema_ptr_
->
release
)
{
schema_ptr_
->
release
(
const_cast
<
ArrowSchema
*>
(
schema_ptr_
));
}
}
/**
* @brief Get the number of rows in the table.
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment