Skip to content

Conversation

@yomotsu
Copy link
Contributor

@yomotsu yomotsu commented Apr 15, 2018

CSS3Renderer caches CSS3DObject's css styles in a scoped pool.

However, once the style is added to the pool, it will never be removed, even with scene.remove( css3DObject ), then memory leak occurs.

This PR is to solve the possibility of memory leak.

@mrdoob
Copy link
Owner

mrdoob commented Apr 15, 2018

I think I would use a WeakMap instead.

@mrdoob mrdoob added this to the r92 milestone Apr 15, 2018
@yomotsu
Copy link
Contributor Author

yomotsu commented Apr 15, 2018

make sense and sounds better, I will change it thanks!

function zOrder( scene ) {
function filterAndFlatten( scene ) {

var order = Object.keys( cache.objects ).sort( function ( a, b ) {
Copy link
Contributor Author

@yomotsu yomotsu Apr 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only for IE11 (to sort by Z).
Cached Object.keys will not work anymore, since it cached in a WeakMap. To make an array, I added a function called filterAndFlatten

@yomotsu
Copy link
Contributor Author

yomotsu commented Apr 16, 2018

Now it uses a WeakMap for the cache. It works even in IE11😊
Here is the examples.
https://rawgit.com/yomotsu/three.js/dev-css3-cache/examples/index.html?q=css

@mrdoob mrdoob merged commit 5196f15 into mrdoob:dev Apr 17, 2018
@mrdoob mrdoob changed the title CSS3Renderer may cause memory leak CSS3DRenderer: Use WeakMap for styles cache. Apr 17, 2018
@mrdoob
Copy link
Owner

mrdoob commented Apr 17, 2018

Thanks!

Repository owner deleted a comment Apr 19, 2018
@yomotsu yomotsu deleted the dev-css3-cache branch April 30, 2018 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants