xles / hyphenator

Automatically exported from code.google.com/p/hyphenator
GNU General Public License v3.0
0 stars 0 forks source link

Memory leak: elements removed from DOM are still not removed from the ElementCollection #192

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Page with ajax request that occurs every X seconds
2. Ajax request replaces HTML text that was hyphened
3. In the next cycle, the elements are still in the ElementCollection

What is the expected output? What do you see instead?
Hyphened elements that are removed from DOM when a javascript event occurs, 
should be removed from the ElementCollection

What version of the product are you using? On what operating system?
Seen in hyphenator 4.1.0

Please provide any additional information below.
"Element" objects that no longer exist in the DOM should be garbage collected. 
Otherwise a memory leak might occur, leading to a large ElementCollection array.

If no automatic garbage collection can be done, add garbage collection method 
which can be triggered by the user when he considers it needed.

You can see this happening on http://www.tijd.be/beurzen/euronext-brussel/bel20 
where the callback from /ajax/newsteaser will trigger Hyphenator.run() and leak 
elements

Original issue reported on code.google.com by slyold...@gmail.com on 28 Aug 2013 at 3:04

GoogleCodeExporter commented 9 years ago
Hi

This is a very interesting issue. And thanks for the detailed report!

You're right: there's no method to remove elements from ElementCollection when 
they are removed from the DOM. I'll have to fix this!

But (there's always a 'but' ;-)
It's not a good idea to call Hyphenator.run() on each ajax-request! This method 
does a lot of work.
Use Hyphenator.hyphenate([…]) 
[http://code.google.com/p/hyphenator/wiki/en_PublicAPI#mixed_Hyphenator.hyphenat
e(mixed_target,_string_lang)] instead. This will not use ElementCollection.

(note: Hyphenator.run() is going to be a singleton in a later release)

Original comment by mathiasn...@gmail.com on 30 Aug 2013 at 7:45

GoogleCodeExporter commented 9 years ago
See example here: 
http://hyphenator.googlecode.com/svn/tags/Version%204.1.0/testsuite/test46.html

Further notes:
- use 
http://hyphenator.googlecode.com/svn/tags/Version%204.1.0/mergeAndPack.html to 
minimize Hyphenator.js and optionally include the patterns
- you are calling 'Hyphenator.reduceHyphenationScope = true;' in 
onhyphenationdoencallback what is this? (just wondering)

Original comment by mathiasn...@gmail.com on 30 Aug 2013 at 7:53

GoogleCodeExporter commented 9 years ago
https://code.google.com/p/hyphenator/wiki/en_FAQ#How_to_hyphenate_text_that_has_
been_loaded_with_AJAX?

Does this not contradict the notion of not calling Hyphenator.run() on each 
ajax-request?

Original comment by doucetni...@gmail.com on 2 Sep 2013 at 10:33

GoogleCodeExporter commented 9 years ago
Yes somehow.
The example on 
https://code.google.com/p/hyphenator/wiki/en_FAQ#How_to_hyphenate_text_that_has_
been_loaded_with_AJAX? just inserts one element. There's no problem with that.
But if you do lots of insertions the issue from above  occurs.

Original comment by mathiasn...@gmail.com on 2 Sep 2013 at 2:20

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
ReduceHyphenationScope was just a bit of a hack to make sure that the 
contentselector was only set after the "full page" hyphenator.run ran. Because 
if it ran before, it was actually not working on the rest of the page. Timings 
and ajax timing stuff huh..
I'm on holiday, my colleague will surely follow up this issue, tnx for picking 
it up.

Greets from hawaii

Original comment by slyold...@gmail.com on 4 Sep 2013 at 6:20

GoogleCodeExporter commented 9 years ago
This has not been fixed yet!
The current solution with Observers is not available in older browsers.
Needs better documentation…

Original comment by mathiasn...@gmail.com on 14 Mar 2014 at 7:46

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
OK, round-up:
- Hyphenator.run() should only be called once. Any subsequent call to 
Hyphenator.run() emits a warning.
- Newly added elements have to be hyphenated with 
https://code.google.com/p/hyphenator/wiki/en_PublicAPI#mixed_Hyphenator.hyphenat
e(mixed_target,_string_lang)

Doing that there's no memory leak in Hyphenator.js (at least I can't reproduce 
it)
Some browsers may leak if the elements are not properly removed from the DOM, 
though…

Original comment by mathiasn...@gmail.com on 17 Oct 2014 at 8:05