W3C home > Mailing lists > Public > www-dom@w3.org > July to September 2001

Re: Range.detach() questions

From: Joseph Kesselman <keshlam@us.ibm.com>
Date: Tue, 14 Aug 2001 15:59:54 -0400
To: www-dom@w3.org
Message-ID: <OF1ADBEA82.2AB8F551-ON85256AA8.006C9D44@pok.ibm.com>

>In languages that support garbage collection, such as Java and
>JavaScript, is it safe to allow a Range object to be garbage collected
>even if detach() has never been called?

Safe?  Yes.  Wise? Probably not.

As you guessed, maintaining a Range as a "live view" -- like maintaining a
NodeIterator -- generally consumes some computational resources in addition
to its storage resources. The Range must be informed of document mutations
so it can update itself correctly. In most DOMs that probably won't be a
huge cost per object, but if you have a loop which is creating these fairly
often it could become significant.

If you don't call detach(), the objects will continue to demand those
resources to maintain themselves until the garbage collector gets around to
removing them.

Calling detach() tells them that they can stop maintaining themselves
_now_, and immediately releases the computational resources... even if the
storage resources persist until the GC gets around to recovering them.


>May implementations in languages without automatic memory management
>require that the detach() method must be called before a Range object is
>freed up?

The DOM spec per se doesn't address this. I'd say that decision is the
binding's responsibility, since that's where the memory management policy
and mechanisms are set. But I'd advise that you wait for a consensus on
this one rather than taking my answer.

______________________________________
Joe Kesselman  / IBM Research
Received on Tuesday, 14 August 2001 16:00:37 GMT

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