// Release has to free the whole tree: the array nodes, the schema nodes, and // the storage their buffers point into. Nothing here asserts that directly - // the sanitizers tests/run.sh builds this with are the assertion, and a node // that leaks per frame is a node that dies on a long run. #include "arrow/array.h" #include #include #include #include namespace { void release(arrow_c::Exported& exported) { exported.array.release(&exported.array); exported.schema.release(&exported.schema); // A released struct marks itself, which is how a consumer knows not to // release it twice. assert(exported.array.release == nullptr); assert(exported.schema.release == nullptr); } } // namespace int main() { const std::vector pixels(4 * 4 * 3, 7); const std::vector depth(4 * 4, 1500.0F); const std::string state = "streaming"; for (int i = 0; i < 100; ++i) { arrow_c::Exported image = arrow_c::image(4, 4, "bgr8", pixels.data(), pixels.size()); assert(image.array.length == 1); assert(image.array.n_children == 4); release(image); arrow_c::Exported depth_image = arrow_c::image(4, 4, "32FC1", reinterpret_cast(depth.data()), depth.size() * sizeof(float)); release(depth_image); arrow_c::Exported values = arrow_c::float32(depth.data(), depth.size()); assert(values.array.length == static_cast(depth.size())); release(values); arrow_c::Exported text = arrow_c::string(state.data(), state.size()); assert(text.array.length == 1); release(text); } return 0; }