Re: Differences beetwen ref and weak ref
- From: Maciej Piechotka <uzytkownik2 gmail com>
- To: Stefan Kost <ensonic hora-obscura de>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Differences beetwen ref and weak ref
- Date: Wed, 18 Jan 2006 09:11:24 +0100
2006/1/18, Stefan Kost <ensonic hora-obscura de>:
Hi,
Uzytkownik wrote:
I'm so sorry - when should I use weak reference?
I use waek references in the class collaboration hierarchy. Imagine classes
GGroup and GItem, where GGroup has GItems. GItem instances need access to
GGroup, thus they have a GGroup *container element;. When setting the container
element for an item I use a weak ref to not introduce a circular dependency
(GGroup references GItem and GItem references GGroup). This works as whenever
GGroup gets destroyed it will release all GItems.
So one might ask when I take the weak_ref at all? I something is behaving wrong
like I unref an GGroup too often, I will access dead memory. When using the
weak_ref the GGroup pointer will be set to NULL and my assertions will trigger
when doing checks like G_IS_GROUP(self->container).
Hope that this makes any sense for you :)
Stefan
Yes. Thank you.
Regards
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]