Re: Differences beetwen ref and weak ref

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 :)


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