[zeromq-dev] Ruby GC

Morten Møller Riis mortenmoellerriis at gmail.com
Wed Dec 21 13:13:27 CET 2011


Thank you Chuck!!!

I cannot believe I didn't catch that. I actually never write it like that but rather like you suggest - hence my other code works perfectly.

I spend hours debugging this looking at pretty much everything else and finally narrowing it down to the GC, which of course was correct.

I am quite happy that my holiday vacation starts today :)

Again, thanks a lot for your quick reply!

Mvh
Morten Møller Riis



On Dec 21, 2011, at 2:20 AM, Martin Sustrik wrote:

> 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
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20111221/37a814d6/attachment.htm>


More information about the zeromq-dev mailing list