pitrou commented on a change in pull request #7753:
URL: https://github.com/apache/arrow/pull/7753#discussion_r454489525



##########
File path: python/pyarrow/jvm.py
##########
@@ -28,24 +28,38 @@
 import pyarrow as pa
 
 
-def jvm_buffer(arrowbuf):
+class _JvmBufferNanny:
+    """
+    An object that keeps a org.apache.arrow.memory.ArrowBuf's underlying
+    memory alive.
+    """
+
+    def __init__(self, jvm_buf):
+        self.jvm_buf = jvm_buf
+        self.jvm_buf.retain()
+
+    def __del__(self):
+        self.jvm_buf.release()
+
+
+def jvm_buffer(jvm_buf):
     """
     Construct an Arrow buffer from org.apache.arrow.memory.ArrowBuf
 
     Parameters
     ----------
 
-    arrowbuf: org.apache.arrow.memory.ArrowBuf
+    jvm_buf: org.apache.arrow.memory.ArrowBuf
         Arrow Buffer representation on the JVM.
 
     Returns
     -------
     pyarrow.Buffer
         Python Buffer that references the JVM memory.
     """
-    address = arrowbuf.memoryAddress()
-    size = arrowbuf.capacity()
-    return pa.foreign_buffer(address, size, base=arrowbuf)
+    address = jvm_buf.memoryAddress()

Review comment:
       Do you mean the object could be collected from another thread?




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

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


Reply via email to