[cairo] memory leak in _cairo_pattern_create_solid

Behdad Esfahbod behdad at behdad.org
Sat Oct 13 15:09:25 PDT 2007


On Fri, 2007-10-12 at 06:47 -0400, Nguyen Vu Hung wrote:
> 
> 
> It seems that cairo_debug_reset_static_data() calling fixes the memory
> "leak" made by cairo_create();. I am now fine with

Lets make it clear.  It's NOT a leak.  And valgrind very clearly says
that 0 bytes were leaked.  What you see is simply reachable memory.  And
it's totally fine.

> cairo_create();
> cairo_debug_reset_static_data();
> 
> No more leak.

...

> The next cairo API that I am having problem with is cairo_show_text().
> In my ( real production ) application, it has to call
> cairo_show_text() about 60,000,000 ( sixty millions ) times.
> For the following code, valgrind reports that cairo_show_text()
> creates an amount of 178,143 bytes memory leak.

That's not leaking either.  It's loading the font and caching glyph
information.

> Therefore, of course, if I call cairo_show_text() 60,000,000 times,
> the system will run out of memory. 

This logic is broken.  You will have a much easier time if you forget
about valgrind for a bit, just write the code and see that it works.
It's good to use valgrind regularly, but look for leaks in your code,
not libraries you use.  Chances that the libraries you use are leaking
is pretty slim...

-- 
behdad
http://behdad.org/

"Those who would give up Essential Liberty to purchase a little
 Temporary Safety, deserve neither Liberty nor Safety."
        -- Benjamin Franklin, 1759





More information about the cairo mailing list