nooberfsh commented on issue #5214:
URL: https://github.com/apache/arrow-rs/issues/5214#issuecomment-1859140624

   Hi, I I have simplify the code and use `ArrowWriter` directly.
   I found  `ArrowWriter` will not release memory after `ArrowWriter::close()` 
according to heaptrack.
   
   ```
   fn main() -> Result<()> {
       leak()?;
       println!("sleep");
       std::thread::sleep(Duration::from_secs(1000));
       Ok(())
   }
   
   fn leak() -> Result<()> {
       let schema = Arc::new(Schema::new(vec![Field::new("col1", 
DataType::Utf8, true)]));
   
       let mut writer = ArrowWriter::try_new(Empty::default(), schema.clone(), 
None)?;
       for _ in 0..1000 {
           let batch = gen_batch(1000, schema.clone());
           writer.write(&batch)?;
       }
       writer.close()?;
       Ok(())
   }
   
   fn gen_batch(size: usize, schema: SchemaRef) -> RecordBatch {
       let mut buf = StringBuilder::new();
       for i in 0..size {
           let s = vec![i as u8; 1000];
           let s = String::from_utf8_lossy(&s);
           buf.append_value(s);
       }
       let col1 = Arc::new(buf.finish());
       RecordBatch::try_new(schema, vec![col1]).unwrap()
   }
   
   ```
   
   Steps to reproduce:
   
   - cargo build --release
   - heaptrack ./target/release/parquet_mem_leak
   - wait screen to show *sleep* which means `ArrowWriter` has finished writing 
and closed
   - kill the program with `Ctrl-C`, heaptrack will popup and show the leaks,  
the program above leaks ~10MB on my machine.
   
   If I comment out `std::thread::sleep(Duration::from_secs(1000));` , 
heaptrack does not show any leaks related to `arrow`.
   So the question is does `arrow` manages some global buffer or something?  
What I am expected is memory should released immediately after closing the 
writer.
   
   
![parquet_mem_leak](https://github.com/apache/arrow-rs/assets/6291629/97ef061e-762c-407d-9e1b-d3f770caf051)
   
   


-- 
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