Questions tagged [space-leak]

Space leak in lazy languages like Haskell refers to a situation when a program uses much more memory than seemingly needed and anticipated.

Space leak in lazy languages like Haskell refers to a situation when a program uses much more memory than seemingly needed and anticipated.

28 questions
3
votes
1 answer

Haskell Space Leak

all. While trying to solve some programming quiz: https://www.hackerrank.com/challenges/missing-numbers , I came across with space leak. Main function is difference, which implements multi-set difference. I've found out that List ':' and Triples…
Chul-Woong Yang
  • 1,223
  • 10
  • 17
3
votes
1 answer

Why does my parallel traversal Haskell program leak memory?

Consider the following Haskell program (I'm doing this mostly for learning purposes): import qualified Control.Concurrent.MSem as Sem import System.Environment (getArgs) import Control.Concurrent (forkIO) import Control.Monad -- Traverse with…
static_rtti
  • 53,760
  • 47
  • 136
  • 192
2
votes
2 answers

Space leak in Haskell - old compiler's fault or mine? Apparently the latter

I recently took part in a competitive coding competition. This Haskell gave a space leak on the judge system running ghc 7.6.3: t n [] = 0 t n ('8':rest) = t (n+1) rest t n (')':rest) = n + (t n rest) main = getLine >>= (\l -> print (t 0 l)) After…
Mörkö
  • 211
  • 1
  • 14
2
votes
1 answer

Is there a space leak in this Haskell implementation of LPath?

For fun I'm attempting to write an implementation of the naive longest path algorithm (for finding the length of the longest acyclic path in a cyclic graph). I started with a direct port of the imperative algorithm, which worked and performed fairly…
LogicChains
  • 4,332
  • 2
  • 18
  • 27
1
vote
1 answer

Space Leak on Gloss render of Mutable Image

I used the JuicyPixel library for generating a rendered image and the gloss library for a live preview. The piece of code below causes a Space Leak viewportRenderer :: Viewport Picture viewportRenderer = do eventText <- Color [rgb|#FFFFFF|] .…
Perigord
  • 111
  • 6
1
vote
2 answers

Space leak in dynamic Haskell

I posted this question a few days ago: Haskell performance using dynamic programming and was recommended to use ByteStrings instead of Strings. After implementing the algorithm with ByteStrings, the program crashes, going over the memory…
Free_D
  • 577
  • 3
  • 16
1
vote
1 answer

Apparent space leak in variant upon Brent's "teleporting turtle" algorithm

I have been implementing a variant of Brent's "teleporting turtle" algorithm mapped over all depthward paths through an N-tree for the purposes of value comparison of two different data structures, with my own backtracking algorithm for rolling back…
0
votes
1 answer

Growing stack size w/ inadvertent loop statement - expected behavior?

First the Question - is the behavior below expected logically, or a bug to be reported for GHC? The code below will leak memory (tested on ghc-8.8.4) because ghc seems to add join point and jumps to it at the end of the loop, building up the…
Sal
  • 4,312
  • 1
  • 17
  • 26
0
votes
2 answers

Avoiding space leaks with `mapM` and `foldM` over `State` monad

How do I avoid space leaks while using foldM and mapM over a State monad? Last year's Advent of Code day 20 has a puzzle of generating a map of a maze from instructions on how to walk across it. For instance, the instructions NN gives the maze …
Neil Smith
  • 313
  • 3
  • 10
0
votes
0 answers

Do space leaks consume memory differently than valid lazy algorithms?

Space leak is usually defined by execution of a program that consumes more space than necessary. Is such definition compatible with algorithms that require lazy evaluation for amortized time efficiency? I wonder if these tend to exhibit different…
sevo
  • 4,559
  • 1
  • 15
  • 31
0
votes
1 answer

Haskell bottom-up DP space leak

Apologies if this is too specific, I am new here and not exactly sure what is reasonable. I have been bashing my head against this problem for hours with nothing to show for it. The following code is my implementation of a competitive programming…
Gozz
  • 25
  • 6
0
votes
2 answers

How do I get lazy streaming into the foldl'?

How does one make their own streaming code? I was generating about 1,000,000,000 random pairs of war decks, and I wanted them to be lazy streamed into a foldl', but I got a space leak! Here is the relevant section of code: main = do games <-…
PyRulez
  • 10,513
  • 10
  • 42
  • 87
0
votes
1 answer

Why does this code consume so much heap?

Here is the full repository. This is a very simple test which inserts 50000 random things into the database with the postgresql-simple database binding. It uses MonadRandom and can generate Things lazily. Here is the lazy Thing generator. Here is…
s9gf4ult
  • 862
  • 6
  • 20
1
2