Dot: failure to create cairo surface: out of memory

This is more curiosity, rather than needing a solution (although solutions are welcome).

I tried adding a large number of nodes to my dot graph today, and started getting an error. If I leave DPI at the default, I get the error “dot: failure to create cairo surface: out of memory”. If I reduce the DPI to 64, or set the page size, my graph works.

It currently has about 350 nodes and 400 edges, and most nodes are ranked; the dot file is a bit over 1000 lines. The resulting JPG is large: 10554 x 14332 @ 64 DPI. If printed at full resolution, it would be 164 inches x 223.93 inches, or 13.74 feet 18.66 feet. I had hoped to print this, but that’s far too big to fit on my wall. Forcing the page size to 8’ x 6’ allows dot to build the graph, but even that size is too large. Most of the text is the default size, so even setting it to 8’ x 6’ makes the text kind of small.

I’m running version 2.44.1 on Windows 10. Using Task Manager, the highest I’ve seen the memory is between 600MB-700MB. Clearly, adding a lot of new nodes caused the problem to appear. Is there a limit on the number of nodes and edges? I may have to scale back my plans if I’m getting close to a node limit. Since my goal is to print this, setting the page size isn’t limiting me. Alternatively, is there a way around this error?

350 nodes and 400 edges is not that complex (in my estimation).
If my math is correct, at 164" x 224", that gives ~ 105 square inches per node! Or more than an 8.5 x 11 page of paper per node! (I question my calculator)
Anyway, try your dot command again with -Tdot. This will calculate the node & edge placement without translating to any output file format. See how much memory is used and how fast it runs.
You can try other output formats besides (gif, png, or even svg). I’d try svg first, search Google for tile large svg.

But if my math is correct, you might consider reformatting your graph to make it more dense/regular.

I’m working on a timeline, and all the nodes have a rank to a year. In many cases, there are edges that span hundreds of years, so the nodes are spread out in the graph.

I must have been doing something wrong, because I was able to get it working again. I shuffled some of the nodes around in the dot file and did a bit of optimization.

If you can create an issue on the Graphviz tracker and attach your original input, we could try to debug this. It does indeed seem odd to get an “out of memory” message if you’re not out of memory.

I just created an issue on the Graphviz tracker.