Re: Differences beetwen ref and weak ref



On Tue, Jan 17, 2006 at 05:35:33PM +0000, Uzytkownik wrote:
I'm so sorry - when should I use weak reference?

Weak reference is a method to get notified that an object
was destroyed.  Maybe it is better to not think about them
as about references at all.

When you take a [real] reference on an object, its refcount
increases and it will not be destroyed even if everything
else releases its references -- because of your reference.
Sometimes you want to keep a pointer to an object while not
preventing it from destruction.  If you simply removed the
g_object_ref(), you'd have a pointer, but you would not know
whether it is still valid.  So you use a weak reference/weak
pointer.

Yeti


--
That's enough.



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