[zeromq-dev] Why do we need to call zmq_term on application exit?

Pieter Hintjens ph at imatix.com
Tue Feb 18 08:57:08 CET 2014


There are two reasons to call zmq_ctx_term. One is to flush messages,
in some use cases. Closing a socket won't wait for messages to be
sent.

The other reason in C at least is to ensure all memory is freed at
exit, so you can run under memory leak checkers like valgrind, to
catch other leaks. If you don't terminate the context (and close all
sockets) you will get masses of reports on those, and miss others.

In languages that can destroy objects automatically when they go out
of scope, you don't need to call zmq_ctx_term.
-Pieter

On Tue, Feb 18, 2014 at 2:48 AM, Matthew Darnall <dnallicus at gmail.com> wrote:
> I have read a couple good posts about how to clean up zmq when exitting an
> application to prevent hanging.  For instance:
> http://zguide.zeromq.org/page:all#Making-a-Clean-Exit
> and
> http://zeromq.org/whitepapers:0mq-termination
>
> One thing I am not sure of though: why do we need to call zmq_term at all if
> we are exiting an application? Won't the OS just release all the resources
> automatically when the process finishes?  I can understand closing sockets
> during the execution of the application to free resources, but why do we
> need to call zmq_term before the application exits?
>
> Thanks,
> Matt
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>



More information about the zeromq-dev mailing list