[DOM]: Don't cache throw away elements. #1773
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Whenever you use
Y.Node.create
or the like, it'll create a "dummy" element under the hood to do its work on. This dummy element is cached in_fragClones
, while it's children are intermittently removed later on. Since this dummy element is never cleared from the cache, a small (potentially) memory leak is caused.I suppose the idea behind caching dummy elements in
_fragClones
was to avoid the constant creation of these elements when usingY.Node.create
.If you look closely,
cloneNode(false)
is called if the particular dummy element is found in the cache. Shallow cloning an element is hardly faster than simply creating it from scratch. The difference in speed is in the noise. See: http://jsperf.com/clone-vs-create-part-deuxI rather us avoid caching the dummy element to avoid the memory leak all together since speed is not a factor.