diagrams / diagrams-contrib

User-contributed extensions to diagrams
BSD 3-Clause "New" or "Revised" License
27 stars 31 forks source link

Memory leak using gridWithHalves #69

Open jwiegley opened 7 years ago

jwiegley commented 7 years ago

I tried to make an nearly empty grid 1000 by 1000 cells, but after it used 40 GB of system memory I had to kill it. Sample code:

{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}

module Main where

import Control.Lens hiding ((#))
import Data.Default
import Data.List
import Data.List.Split
import Data.Typeable
import Diagrams.Backend.SVG.CmdLine
import Diagrams.Prelude
import Diagrams.TwoD

default (Int)

example :: Int -> Int -> [((Int, Int), (Double, Double), Colour Double)]
        -> Diagram B
example n m =
    foldr (\((x, y), (w, h), c) -> situate x y w h c)
        $ gridWithHalves n m
  where
    situate x y w h c =
        flip placeDiagramOnGrid [((x*2)+1, (y*2)+1) :: (Int, Int)]
            $ rect (w / fromIntegral n) (h / fromIntegral m)
                # alignTL
                # lc c
                # fc c

main :: IO ()
main = mainWith $ example 1000 1000 shapes
  where
    shapes = [ ((3, 4), (2, 2), black)
             , ((5, 7), (3, 1), red)
             ]