There are really two detach
methods: the one on native ranges (those ranges created by document.createRange()
), and the method that Rangy exposes on its range objects.
DOM's detach
The reason for detach
being there at all is that it is mandated by the DOM Level 2.
Now, going by the discussion in this bug report, the idea of detach
was that it should enable the browser to free up computational resources. As long as a range is in use, the browser has to track it. Judging by the discussion in the bug report, the following appear to be true:
Few applications call
Range.detach
.In Firefox, it is a noop.
Moreover, the WHATWG makes it a noop so it is likely that browsers will follow suit sooner or later.
Rangy's detach
The detach
method that Rangy puts on its ranges calls the DOM's method and performs some internal bookkeeping.
Looking at Rangy's code, I see nothing there that would suggest that calling detach
on a range created by Rangy would prevent garbage collection problems.
I was wondering what Tim Down (author of Rangy) thought about it, and I found a post by him here. He seems to be on board with getting rid of detach()
. Probably it will take a while before Rangy removes it if only to be backward compatible.
So I would not bother calling it.