Re: Range.detach() questions

>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 UTC