I have a document with some TikZ images in it, which are automatically generated from a program I have written. All images are fairly similar, and each of them contains of a large number of squares with different, arbitrary rgb colors. My question is: What is the best way of coloring all this large number of squares?
The method I have used so far consists of defining the color fillcolor by using the macro \definecolor, before drawing each square, and of using that color to fill the square. That means that each time I'm drawing a new square, I'm defining fillcolor again.
However, I'm not so sure that is the way to do it. pdflatex seems to require very much memory when compiling the document, and, for some strange reason, runs out of memory if I include more than 5 of the images (even if I increase the amount of memory tenfold when going from 5 to 6 images). Is there any chance that it stores all the colors I have defined, and that I need to make pdflatex "forget" about fillcolor before calling \definecolor again?
Update: Below is an example of one of the TikZ images I want in my document (it's a vizualization of the phase fraction field in a two-phase fluid simulation using the finite volume method and the volume of fluid method, and yes, I know, the fluid interface isn't exactly crisp):

This particular image consists of 1990 filled squares and 4 unfilled squares.
First, for each square, fillcolor is defined with \definecolor, and the square is filled with that color:
\definecolor{fillcolor}{rgb}{1.000000,0.241735,0.000000}
\fill[fillcolor] (0.203125,0.578125) rectangle (0.218750,0.593750);
Then the sides of each square is drawn, for example
\draw (0.203125,0.578125) rectangle (0.218750,0.593750);



\foreach. – Sigur Dec 21 '13 at 13:19\definecolorare stored in a internal macro. If so, redefining it will recycle the same macro, and thus will not use more memory. – JLDiaz Dec 21 '13 at 13:20\definecolorsimply redefinesfillcolor; there is no memory leak in it. – Christian Feuersänger Dec 21 '13 at 14:45git bisectandgit clean -fx, I managed to find the commit where it did no longer compile; I had included a page from a pdf file using thepdfpagespackage — apparentlypdfpagesand TikZ-PGF seems to be a poor combination. What is still very strange is that prior to including the page from the file, which is just 196 kB, pdflatex only used ~929K words. Afterwards, 3M words was not enough. – StrawberryFieldsForever Dec 22 '13 at 14:22