[plt-dev] Async channels and GC

From: Jakub Piotr Cłapa (jpc-ml at zenburn.net)
Date: Sun Dec 20 09:26:57 EST 2009


I recently switched from normal channels to the asynchronous ones to 
harden my code against clients disappearing during an RPC (so the server 
won't wait indefinetely to send the reply when a break occurs in the 
client during the RPC).

I was creating a new channel for every RPC call. The no-argument RPC 
call is made like this:
(let ([chn (make-channel)])
   (thread-send s-thd chn)
   (channel-get chn))

Unfortunately async-channels were not getting garbage collected until 
both the client and the server threads have been killed (by kill-thread 
or custodian-shutdown).

I attach a test-case which makes 15000 RPC calls and reports 
(current-memory-use) after the test and after killing the client and 
server threads. When using async-channels Scheme reports very large 
memory usage after the call to collect-garbage. The number drops only 
after I kill both threads. The synchronous case behaves as expected 
(killing the threads after garbage-collection has neglible impact on 
memory use).

Am I missing something or is it a memory leak?

Jakub Piotr Cłapa
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: async-channel-test.ss
URL: <http://lists.racket-lang.org/dev/archive/attachments/20091220/26e1437c/attachment.ksh>

Posted on the dev mailing list.