coderoshi/dds — pull request #1 by kbrock (2013-09-06 05:23:19+00:00)
Title: don't leak contexts

Hello,
these examples are great.

# Problem

On my computer, after 42 put requests, it runs out of file descriptors, because too many contexts are created and not cleaned up.

I interpret [guide][] to say you need only 1 context per process, except in rare cases. Don't know enough to elaborate the rare cases. But not terminating the context isn't good.

[guide]: http://zguide.zeromq.org/page:all#Getting-the-Context-Right

# Suggested Solution

I modified connect to cache it in the process, and that fixes it.

Played around with using the block / auto close syntax and liked it.

I can fix change request to go across all code, but didn't know if you wanted:

- `@ctx` variable vs passing `context` in
- `connect` and explicit `close` style vs `communicate` block style with auto closing of the socket. (if you like `communicate`, I could change `connect` to look like `communicate`)

Point me in the right direction and I can change this pull request to incorporate all examples.

Thanks again for the great examples. This is my first entry into zeromq.
--Keenan