[zeromq-dev] Java: reference to context from socket

gonzalo diethelm gdiethelm at dcv.cl
Tue Aug 3 00:27:55 CEST 2010


Hello, long time no see...

I modified class Socket to hold a local reference to the passed-in
context, so that Java's GC won't be too eager to free the context while
there are sockets in use.

I used to have commit access to the Java repo, but it seems I lost it
when it was moved from sustrik to zeromq. Hence I am attaching the
patch. It includes many lines because I modified the end-lines to be
Unix-compliant (LF), the real change is as follows. I understand LF is
the norm in this project, if I am wrong I send my apologies in advance.

Best regards.


$ git diff -w origin/master
diff --git a/src/org/zeromq/ZMQ.java b/src/org/zeromq/ZMQ.java
index 0e239d5..a90e357 100755
--- a/src/org/zeromq/ZMQ.java
+++ b/src/org/zeromq/ZMQ.java
@@ -201,6 +201,9 @@ public class ZMQ {
          */
         protected Socket (Context context,
                           int type) {
+            // We keep a local handle to context so that
+            // garbage collection won't be too greedy on it.
+            this.context = context;
             construct (context, type);
         }

@@ -224,6 +227,8 @@ public class ZMQ {

         /** Opaque data used by JNI driver. */
         private long socketHandle;
+
+        private Context context = null;
     }


-- 
Gonzalo Diethelm 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Added-in-Socket-a-reference-to-Context-so-that-Java-.patch
Type: application/octet-stream
Size: 25867 bytes
Desc: 0001-Added-in-Socket-a-reference-to-Context-so-that-Java-.patch
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20100802/79f01d48/attachment.obj>


More information about the zeromq-dev mailing list