Re: Memory ownership from pango_context_load_font(..)



Sorry for the long delay, it was difficult to explain the problem and
when I finally understood it the solution was straight forward.

The symptom as I said earlier was that abiword would *sometimes* crash
on exit due to a segfault with pango-cairo.

The backtrace should it orginating in Cairo Graphics class destructor.

The original code was this:

	_destroyFonts();
	delete m_pPFontGUI;
        if(m_pLayoutFontMap)
                g_object_unref(m_pLayoutFontMap);
	if(m_pLayoutContext)
		g_object_unref(m_pLayoutContext);


The fix was to do the following. The comments explain why it is (I
think) OK and won't cause a memory leak.


	_destroyFonts();
	delete m_pPFontGUI;
	if(m_pLayoutContext)
		g_object_unref(m_pLayoutContext);

	// MES After much reading and playing I discovered that the
	// FontMap gets unreferenced after every font that uses it is
	// removed provided the Context is also unrefed. Leaving the unref of
	// the FontMap causes an intermitent crash on exit, particularly on
	// documents with lots of Math. This fixes those crashes and checks with
	// valgrind show no measureable increase in leacked memory.
	//
	m_pLayoutFontMap = NULL;
-----------------------------------------------------------------------------------------------

Do you think this is valid? Will the final
g_object_unref(m_pLayoutContext) also do the an unref on the FontMap
and so delete it?

Cheers!

Martin

}
On Tue, May 12, 2009 at 1:19 AM, Behdad Esfahbod <behdad behdad org> wrote:
> On 05/11/2009 11:08 AM, Martin Sevior wrote:
>>
>> Is the only way to free a PangoFont * pF to do
>>
>> g_object_unref(pF)
>> ?
>
> Yes.
>
>> Is there pango_font_free(pF) or similar?
>
> No.
>
> What's the problem you are facing?  The caching stuff in pangofc is quite
> complex.  I may be able to help if you describe what anomaly you are seeing.
>
> behdad
>
>> Thanks again!
>>
>> Martin
>>
>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]