[zeromq-dev] Ruby GC
Martin Sustrik
sustrik at 250bpm.com
Wed Dec 21 02:20:09 CET 2011
On 12/21/2011 06:25 AM, Chuck Remes wrote:
> This isn't new for 2.1. I think you are just getting lucky on that
> other code.
>
> The problem is this line:
>
>> @socket = ZMQ::Context.new.socket(ZMQ::UPSTREAM)
>
>
> You are not saving a reference to the context that you just created,
> so the GC will reap it at some point. Change it to:
>
>> @context = ZMQ::Context.new @socket =
>> @context.socket(ZMQ::UPSTREAM)
>
> And now all will be well with the world.
IIRC Java binding was facing this problem already.
What they've done was to hold a Java reference to every socket created
in the context:
https://github.com/zeromq/jzmq/blob/master/src/org/zeromq/ZContext.java#L32
That prevents gc to deallocate the context while there are sockets still
around.
Martin
More information about the zeromq-dev
mailing list