Status: New
Owner: ----
New issue 2869 by [email protected]: Substring of huge string retains
huge string in memory
http://code.google.com/p/v8/issues/detail?id=2869
Steps to reproduce:
var s = "a huge, huge, huge string...";
s = s.substring(0, 5);
Expected results: s takes five bytes of memory, plus some overhead.
Actual results: s takes a huge, huge, huge amount of memory.
Unfortunately, most String functions use substring() or no-ops internally:
concatenating with empty string, trim(), slice(), match(), search(),
replace() with no match, split(), substr(), substring(), toString(),
trim(), valueOf().
My workaround is:
function unleakString(s) { return (' ' + s).substr(1); }
But it's not satisfying, because it breaks an abstraction and forces me to
think about memory allocation.
Perhaps there should be some special logic for handling substring() when
the output string length is less than, say, 0.125 times the input string
length? that's not perfect, but in my opinion, the pros of this solution
outweigh the cons.
This crops up constantly when scraping HTML.
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.