CurtHagenlocher commented on issue #540:
URL: https://github.com/apache/arrow-dotnet/issues/540#issuecomment-7417460633

   Retaining isn't only about construction. It needs a rule for every API that 
returns an array: either the caller owns the result and disposes it, or the 
caller borrows it and must not.
   
   - **Owned (unchanged):** results that are new objects, such as `Build()`, 
`ReadNextRecordBatch()`, `Concatenate`, `Clone`, C Data import, and the new 
retaining factories. `SliceShared` already belongs here; `Slice` would join it 
under #541.
   - **Borrowed:** accessors such as `RecordBatch.Column`, 
`StructArray.Fields`, `ListArray.Values`, `DictionaryArray.Dictionary` and 
`IArrowArray.Data`. This is already how they behave: disposing one releases 
memory its parent still uses. #536 documents it.
   
   Other implementations handle accessors differently. In C++, `field(i)` 
returns a `shared_ptr`, so every access adds a reference that its holder 
releases. arrow-rs returns `&ArrayRef`, a borrow that callers `clone()` to 
keep. Arrow Go returns a borrowed array that callers `Retain()` to keep. Making 
every `Column(i)` result something callers must dispose would be painful in C#, 
so accessors should stay borrowed, as in Rust and Go.
   
   Two additions would make that comfortable:
   
   - **A one-step way to take a reference:** something like 
`IArrowArray.Retain()`, so keeping a column is `batch.Column(0).Retain()` 
instead of `ArrowArrayFactory.BuildArray(column.Data.Retain())`.
   - **Harmless disposal of borrowed views:** `Dispose()` on a borrowed view 
would do nothing instead of releasing its parent's memory. This needs care, 
because some accessors return the object the caller passed in rather than a 
view, so it's probably a separate discussion.
   
   So the user-visible changes under retaining are: dispose your own inputs, 
dispose slices, and don't dispose borrowed results (which is already the rule 
today).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to