Memory blowup with images #9

fryguybob opened this Issue Aug 4, 2012 · 3 comments


None yet
1 participant

fryguybob commented Aug 4, 2012

(Imported from Original issue from on August 30, 2011, 02:41:43 PM UTC)

What steps will reproduce the problem?

  1. compile "main = defaultMain $ cat (1,0) (replicate 500 $ cat (0,1) (replicate 500 $ image "any.png" 205 205))"
  2. ./main -ofoo.pdf -w3000 -h3000

Should result in a long wait and foo.pdf with plenty of images. Instead gobbles up all memory in the system.

What version of the product are you using? On what operating system?*


fryguybob commented Aug 4, 2012

(Imported. Original comment by on August 30, 2011, 09:54:50 PM UTC)

It seems to me that there are two potential issues here:

  1. It seems likely that resources allocated for the ImageSurfaces being created are not being freed properly. Do we need to call finishSurface after we are done? I don't yet understand exactly how the cairo API is supposed to be used here.
  2. Another potential problem is that we lose sharing when doing (replicate 500 $ image "foo"), leading to 500 ImageSurfaces being created and destroyed. In this particular case it would be better if we just created a single ImageSurface and then used it repeatedly. A simple way to achieve this would be with a Map from image file names to surfaces. Intuitively it seems like this would be a win; most diagrams using a lot of image primitives will probably have a lot of repeated ones.

However, I understand this was NOT the case for the original diagram which precipitated this bug report! For such diagrams the Map would incur the extra overhead of looking up each new file name in the Map before creating a surface. I guess some profiling is needed to figure out the best general policy.


fryguybob commented Aug 4, 2012

(Imported. Original comment by on November 2, 2011, 06:36:31 PM UTC)

OP, see Issue 57 that I've just filled. Maybe your problem is not only with image but also with "cat".



fryguybob commented Aug 4, 2012

(Imported. Original comment by on November 16, 2011, 12:50:37 PM UTC)

Perhaps it is. "cat" seemed to make a small difference, but the example still eats the memory and I'm inclined to think that finishSurface or some other resource freeing call is needed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment