[Haskell-cafe] Space leak with recursion
Martijn Rijkeboer
haskell at bunix.org
Fri Apr 24 09:34:25 UTC 2015
>> Once thee space leak is fixed I will need to add code to increment the
>> sequence number (not yet implemented).
>
> In that case the most important thing to do is to try to reproduce the
> space leak without the snapshot socket.
I've just ran the code below (removed the snapshot socket) and the
space leak is still there. Since I don't have access to a Windows
box at the moment this was tested on the following configuration:
- OS: Ubuntu 14.04 (64-bit)
- GHC: 7.8.4 (64-bit)
- Zeromq4-haskell: 0.6.3 (Stackage LTS 2.4)
- ZeroMQ: 4.0.4 (64-bit)
> Very sensible. I was confused for a moment whether the minimal version
> did actually exhibit the space leak behaviour.
>
> To get the state-updating behaviour you want, I suggest you use
> `StateT IO` rather than `IO`. With handlers in the `StateT IO` monad
> the state updates will occur as you expect.
Thanks for the suggestion I'll try that, but it will take me some time.
Kind regards,
Martijn Rijkeboer
--- code ---
module Observable
( run
) where
import Control.Monad (void)
import Data.Int (Int64)
import System.ZMQ4
data State = State
{ nextSeqNum :: !Int64
, listenSocket :: !(Socket Pull)
}
run :: IO ()
run = do
withContext $ \ctx ->
withSocket ctx Pull $ \observer -> do
setLinger (restrict (0::Int)) observer
bind observer "tcp://*:7010"
let state = State
{ nextSeqNum = 0
, listenSocket = observer
}
pollSockets state
pollSockets :: State -> IO ()
pollSockets state =
void $ poll (-1) [ Sock (listenSocket state) [In] (Just $
observerHandleEvts state) ]
observerHandleEvts :: State -> [Event] -> IO ()
observerHandleEvts state _ = do
void $ receiveMulti $ listenSocket state
-- TODO: update state by incrementing the nextSeqNum
pollSockets state
More information about the Haskell-Cafe
mailing list