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

Martin Sustrik sustrik at 250bpm.com
Tue May 11 19:54:35 CEST 2010


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

Yes. You are right. The message is never deallocated. I've committed the 
fix.

Thanks!
Martin



More information about the zeromq-dev mailing list