Re: Unreferencing. The sick tny_folder_iface_uncache has been removed and replaced by an autodetect mechanism
- From: Philip Van Hoof <spam pvanhoof be>
- To: tinymail-devel-list gnome org
- Subject: Re: Unreferencing. The sick tny_folder_iface_uncache has been removed and replaced by an autodetect mechanism
- Date: Fri, 25 Aug 2006 11:31:16 +0200
On Fri, 2006-08-25 at 11:11 +0200, Philip Van Hoof wrote:
> Note that while doing all this, I found four serious memory leaks:
>
> All the "set_header" methods in the TnyMsgViewIface implementations
> didn't reparent the header instance. This kept a reference on the
> headers which was of course far more detectable now that the entire
> CamelFolder will be kept alive until the last one is death.
>
> If Modest implements its own TnyMsgViewIface, carefully check the
> differences in libtinymailui-gtk!
The work is committed.
The rule for ALL methods and properties of tinymail types is (or will
be, should be) that they ARE reference neutral. This means:
TnySomeType *instance = tny_some_type_new ();
tny_some_other_type_set_some_type (some_other, instance);
tny_some_yet_another_type_set_some_type (some_another, instance);
g_object_unref (G_OBJECT (instance));
Your instance will not be destroyed until the instances "some_other" and
"some_another" are done with it. This typically happens when you set
another instance using the same "set_some_type" method on the same
"some_other" or "some_another" instance AND when they get destroyed
because they exhausted their own reference count.
void tny_some_other_type_set_some_type (...)
{
if (priv->some_type)
g_object_unref (priv->some_type);
g_object_ref (priv->some_type);
priv->some_type = some_type;
}
void tny_some_other_type_finalize (...)
{
if (priv->some_type)
g_object_unref (priv->some_type);
}
The rule for returned objects for methods ALL tinymail types is that a
reference is added.
TnySomeType* tny_some_other_type_get_some_type (...)
{
return (g_object_ref (priv->some_type));
}
This basically means that you DO need to unreference it after using:
TnySomeType *instance = tny_some_other_type_get_some_type (other_type);
tny_some_type_print_stuff (instance);
tny_some_type_print_more_stuff (instance);
g_object_unref (G_OBJECT (instance));
This is (or should be, will be) the case for ALL tinymail situations.
...
I'm indeed writing this E-mail to punish myself for doing it wrong a few
times myself.
If there's an error in this E-mail, please punish me at a conference ;-)
--
Philip Van Hoof, software developer at x-tend
home: me at pvanhoof dot be
gnome: pvanhoof at gnome dot org
work: vanhoof at x-tend dot be
http://www.pvanhoof.be - http://www.x-tend.be
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]