Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory blowup with images #9

Open
fryguybob opened this issue Aug 4, 2012 · 3 comments
Open

Memory blowup with images #9

fryguybob opened this issue Aug 4, 2012 · 3 comments

Comments

@fryguybob
Copy link
Member

(Imported from http://code.google.com/p/diagrams/issues/detail?id=42. Original issue from alea...@gmail.com 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?*

diagrams-cairo-0.3
diagrams-core-0.3
diagrams-lib-0.3
@fryguybob
Copy link
Member Author

(Imported. Original comment by byor...@gmail.com 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
Copy link
Member Author

(Imported. Original comment by felipe.l...@gmail.com 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".

HTH!

@fryguybob
Copy link
Member Author

(Imported. Original comment by alea...@gmail.com 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
Projects
None yet
Development

No branches or pull requests

1 participant