[_] Javascript removeChild and event listeners
Tom Gidden
tom at gidden.net
Mon Oct 2 13:24:37 BST 2006
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. So probably best if
>> you do clean things up manually before removing the node.
>
> Wot I thought. Cleaning up manually is certainly not going to hurt. I
> shall go with that.
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.
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.
On the other hand, I might be wrong. :) It's been a while since I've
played with this side of things.
Anyway, I think it's *definitely* a good idea to remove the event
listeners by hand.
Tom
--
Tom Gidden
http://gidden.net/tom/
>> Sounds like a 'garbage collection' issue to me -- a concept
>> which I think it alien to JavaScript. So probably best if
>> you do clean things up manually before removing the node.
>
> Wot I thought. Cleaning up manually is certainly not going to hurt. I
> shall go with that.
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.
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.
On the other hand, I might be wrong. :) It's been a while since I've
played with this side of things.
Anyway, I think it's *definitely* a good idea to remove the event
listeners by hand.
Tom
--
Tom Gidden
http://gidden.net/tom/