lua-users home
lua-l archive

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


As the question required the list to be kept existend by a pointer to _any_
element in the list, the solution you gave is insufficient. If the pointer
does not point to the first entry, the weak part will get lost. If you make
the weak part strong you have cycles ;-)

Besides, I think there should be made a difference between garbage
collection in scripting languages and in "native" languages. Scripting
languages do (usually) know everything about their environment like the
stack etc. since they specify and implement it. Therefore they should use
this information in their gc. In "native" languages assumptions about the
environment make the program most times depending on the machine or
operating system.

----- Original Message ----- 
From: "Thatcher Ulrich" <tu@tulrich.com>
To: "Lua list" <lua@bazar2.conectiva.com.br>
Sent: Thursday, May 29, 2003 10:39 PM
Subject: Re: garbage collection thoughts... again?!


> On Thu, 29 May 2003, Enrico Colombini wrote:
>
> > On Thursday 29 May 2003 19:07, Thatcher Ulrich wrote:
> > > * use a weak pointer when you don't "own" the other object.  E.g. a
> > >   child node would have a weak pointer to its parent.  This requires
> > >   some awareness on the part of the programmer of when to use a weak
> > >   pointer, but at least is safe.
> >
> > How do you apply this principle to a doubly-linked list, that could
> > be kept in existance by a single reference to an unpredictable item
> > (e.g. a reference either to the head or to the tail)?
>
> I guess it might look like this:
>
> struct element {
> // some data
> smart_ptr<element> next;
> weak_ptr<element> prev;
> };
>
> And, the list itself must be terminated by NULL, or be explicitly
> broken when you want to collect it.
> [...]