[zeromq-dev] Memory leak in recv() in Java client

Jon Gifford jon at loggly.com
Tue May 11 19:22:09 CEST 2010


Hi,

I've been testing the 0MQ java client, and think I've found a leak in the
recv() method. My test setup (on linux) was

message generator => zmq_streamer => message consumer

both the generator and consumer are java. What I saw was that the consumer
memory size was growing at the same rate at which I was sending it messages.
(I.e. I send 1GB of messages, and it grew by 1GB), which jconsole said the
java heap was behaving nicely (i.e. not growing). This suggested a native
leak (i.e. in the JNI or 0MQ code).

Taking a look at JNIEXPORT jbyteArray JNICALL
Java_org_zeromq_ZMQ_00024Socket_recv (JNIEnv *env, jobject obj, jlong flags)
in Socket.cpp, I noticed that the zmq_msg_t message was never cleaned up, so
I added a zmq_close_message(&message) right before returning, and now there
is no growth in the consumer memory size. Here is the change, with a bit of
context:

346    env->SetByteArrayRegion (data, 0, sz, (jbyte*) pd);
347
348    zmq_msg_close(&message);
349
350    return data;

Since I've only just (in the last week) started playing with 0MQ, I'm not
100% confident that this is the right "fix", so would appreciate some
feedback from someone with a bit more knowledge.

cheers

Jon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20100511/24db011d/attachment.htm>


More information about the zeromq-dev mailing list