[_] Javascript removeChild and event listeners
Jan Grant
jan.grant at bristol.ac.uk
Mon Oct 2 14:12:15 BST 2006
On Mon, 2 Oct 2006, Tom Gidden wrote:
> On 2 Oct 2006, at 13:03, Iwein Dekoninck wrote:
> > > Sounds like a 'garbage collection' issue to me -- a concept
> > > which I think it alien to JavaScript.
Nope, javascript has garbage collection.
> From what I remember, the main problem with GC in Javascript is (as ever) that
> of circular references. In other words, when one Javascript thing refers to
> another thing that refers to it, or does so through a more indirect route.
JS can also clean up circular references.
If the JS interpreter is embedded in a platform that doesn't release
references to JS objects correctly, then that's a bug in the containing
platform. That's quite likely to be the case, I'd expect, since JS event
handlers are probably registered with the containing browser through a
proxy that keeps a reference to the JS in question.
> Although this isn't peculiar to JS, since functions are (all?) first order and
> also commonly used for event listeners, it's extremely easy to set up such
> circular references... often without even realising it. For example, just by
> having a function that refers to an object in some way, without actually
> having to set a variable with a reference as such.
(The python3k list is currently trying to unpick the problem of hard
references to objects in finalisers attached to weak reference
collections, and it's exactly this that's causing heartache.)
--
jan grant, ISYS, University of Bristol. http://www.bris.ac.uk/
Tel +44 (0)117 3317661 http://ioctl.org/jan/
I'm the dandy information superhighwayman.
> On 2 Oct 2006, at 13:03, Iwein Dekoninck wrote:
> > > Sounds like a 'garbage collection' issue to me -- a concept
> > > which I think it alien to JavaScript.
Nope, javascript has garbage collection.
> From what I remember, the main problem with GC in Javascript is (as ever) that
> of circular references. In other words, when one Javascript thing refers to
> another thing that refers to it, or does so through a more indirect route.
JS can also clean up circular references.
If the JS interpreter is embedded in a platform that doesn't release
references to JS objects correctly, then that's a bug in the containing
platform. That's quite likely to be the case, I'd expect, since JS event
handlers are probably registered with the containing browser through a
proxy that keeps a reference to the JS in question.
> Although this isn't peculiar to JS, since functions are (all?) first order and
> also commonly used for event listeners, it's extremely easy to set up such
> circular references... often without even realising it. For example, just by
> having a function that refers to an object in some way, without actually
> having to set a variable with a reference as such.
(The python3k list is currently trying to unpick the problem of hard
references to objects in finalisers attached to weak reference
collections, and it's exactly this that's causing heartache.)
--
jan grant, ISYS, University of Bristol. http://www.bris.ac.uk/
Tel +44 (0)117 3317661 http://ioctl.org/jan/
I'm the dandy information superhighwayman.