lua-users home
lua-l archive

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


I've got lists made up of LUA tables, implemented as dummy-header-node
circularly-linked-lists, with 'next' and 'prev' entries in each table
for linkage.

When I allocate a node, I 'point' the 'next' and 'prev' members at the 
node itself (effectively making it a 0-node list)

	function newNode ()
	    local node = {};
	    node.next = node;
	    node.prev = node;
	    return node;
	end

If I then add this node to a list:

	function addNode (list, node)
		node.prev = list.prev;
		node.next = list;
		list.prev.next = node;
		list.prev = node;
	end

and later remove it by unlinking it from it's peers and then setting it's
next/prev pointers to point to itself...

	function remNode (node)
		node.prev.next = node.next;
		node.next.prev = node.prev;
		node.prev = node.next = node;
	end

Assuming that no other variables reference this table, will it ever be GC'ed?
or should I set the prev/next fields to nil to enable GC?
--
Mike Cuddy (mcuddy@FensEnde.com, MC312), Programmer, Daddy, Human.
Fen's Ende Software, Redwood City, CA, USA, Earth, Sol System, Milky Way.
I remember asking why ... Let it rain, and protect us from this Cruel Sun.

       Join CAUCE: The Coalition Against Unsolicited Commercial E-mail.  
                          <http://www.cauce.org/>