W3C home > Mailing lists > Public > www-dom@w3.org > April to June 1998

RE: Alternative to the Live NodeIterator

From: Peter Sharpe <peter@sqwest.bc.ca>
Date: Fri, 01 May 1998 14:02:58 -0700
Message-Id: <199805012103.OAA14732@sqwest.bc.ca>
To: www-dom@w3.org
At 11:26 AM 5/1/98 , David Brownell wrote:
>> Right. Some object -- and the document tree is a logical choice -- must
>> maintain a reference to iterators.
>
>This seems to derive from the need to be able to identify some
>abstract position "between" iterated nodes.  If the iterator had
>a "current node", I don't think such a reference would ever be
>needed, since simple algorithms would suffice to always find
>the next/previous/first/last nodes and, for tree iterators, the
>firstchild/nextchild/firstsibling/nexsibling nodes.
>
I don't understand this. Maybe I haven't woken up yet this morning
-- see my reply to your next point, below, for proof -- but it
seems to me that whether you are "between" nodes or "on" a node
doesn't affect the underlying implementation much. In other words,
the iterator can contain a reference to a node and information
about its position relative to that node. I think that the iterator
needs two possible states, before or after the node it references.
If it is "on" the node, it doesn't need the state.

>Is anyone claiming that the indexed access model makes sense on
>a live NodeIterator, by the way?
>
Depends on what you mean by "makes sense." I claim the behaviour can
be defined and implemented. Will it always be useful? No.

>> >And as Don Park also mentioned, these reference need a release mechanism.
>>
>> In the subset of language bindings which garbage collect -- I'll include
>> ECMA Script and COM in that category -- I don't believe there is a
>> requirement for adding a release mechanisms to the DOM API. Doesn't Java
>> also fall into the same category?
>
>Java garbage collects ...  but the "reference(s) to the iterators"
>that's maintained by "some object" to maintain "live" semantics will
>preclude collecting any those iterators as garbage!  Iterators will
>always have live references, hence can't be GC'd.
>
And there's the proof that I haven't woken up yet. You are right, of course.
My experience has been with either C++ where we explicitly delete the objects
or a garbage collecting language interface to C++ where the reference in the
list was unknown to the scripting language.

I still think we are OK for ECMAScript and COM for the reason I mentioned
above: the reference from the list will not be known to the scripting
language or the COM interface so garbage collecting or reference counting
will work. The problem comes in the Java bindings. I have no good solution
in that case. You can implement your own memory management at the expense
of interoperability, I guess.

It sounds like the solutions are:
1. Fix up iterators on editing operations and have each Java implementation
provide some interface to releasing iterators.
2. Fix up iterators on editing operations and define an interface in the
DOM that would enable implementations to release iterators.
3. Say in the DOM that the behaviour of iterators after an editing operation
is undefined.

Of these three, I think that I would prefer 1 -- although I can understand
why others wouldn't -- and maybe I could live with 3, but not very happily.
I come from the editor world and my users will use the DOM to transform
parts of their documents. The code does its work by examining nodes in one
area of the tree and inserting nodes in another part of the tree. If the
code uses iterators which become useless after each editing operation then
it is going to be a mess. The reason I could live with it, though, is
because it is possible to do the tree walking using nodes rather than
iterators.

Can you Java experts not find some other way out of this dilemma? I don't
believe Andrew marshall's suggestion of adding a property set to Node
solves the problem. (By the way, if you don't mind adding a memory hit for
each Node, I believe a solution can be found by having Nodes point to
relevant iterators.)

Thanks for waking me up, David.

Peter
---------------------------------------------------------------------------
Peter Sharpe, Chief Scientist, SoftQuad Inc.  Tel: +1 604 585 8394 ext. 312
#108-10070 King George Highway, Surrey, B.C., CANADA V3T 2W4  Fax: 585 1926
Internet: peter@sq.com or peter@sqwest.bc.ca     World Wide Web:
<http://www.sq.com/>www.sq.com  
Received on Friday, 1 May 1998 17:03:38 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:45 GMT