@@ -655,20 +655,20 @@ impl<V: VTable> ArrayEq for ArrayAdapter<V> {
655655}
656656
657657impl < V : VTable > ArrayVisitor for ArrayAdapter < V > {
658- fn children ( & self ) -> Vec < & dyn Array > {
658+ fn children < ' a > ( & ' a self ) -> Vec < & ' a dyn Array > {
659659 // FIXME(ji/node-trav-for-arr): This implementation has issues with lifetime management.
660660 // The visitor pattern gives us &dyn Array with scoped lifetimes, but we need to return
661661 // Vec<&dyn Array> with references that outlive this function. Current approaches:
662662 // 1. Box::leak - works but leaks memory (current impl)
663663 // 2. Unsafe transmute - UB for dynamically-constructed children (e.g., ChunkedArray's chunk_offsets)
664664 // 3. Change signature to iterator-based API
665- struct ChildrenCollector {
666- children : Vec < ArrayRef > ,
665+ struct ChildrenCollector < ' a > {
666+ children : Vec < & ' a dyn Array > ,
667667 }
668668
669- impl < ' a > ArrayChildVisitor < ' a > for ChildrenCollector {
669+ impl < ' a > ArrayChildVisitor < ' a > for ChildrenCollector < ' a > {
670670 fn visit_child ( & mut self , _name : & str , array : & ' a dyn Array ) {
671- self . children . push ( array. to_array ( ) ) ;
671+ self . children . push ( array) ;
672672 }
673673 }
674674
@@ -677,15 +677,7 @@ impl<V: VTable> ArrayVisitor for ArrayAdapter<V> {
677677 } ;
678678 <V :: VisitorVTable as VisitorVTable < V > >:: visit_children ( & self . 0 , & mut collector) ;
679679
680- // Use Box::leak to extend lifetime - THIS LEAKS MEMORY!
681- collector
682- . children
683- . into_iter ( )
684- . map ( |arc| {
685- let leaked: & ' static Arc < dyn Array > = Box :: leak ( Box :: new ( arc) ) ;
686- leaked. as_ref ( ) as & dyn Array
687- } )
688- . collect ( )
680+ collector. children
689681 }
690682
691683 fn visit_children < ' a > ( & ' a self , visitor : & mut dyn ArrayChildVisitor < ' a > ) {
0 commit comments