-
-
Notifications
You must be signed in to change notification settings - Fork 35.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebGLProgram leaking (instances increasing) #28355
Comments
I have debugged the example and it seems the internal program cache does not retain outdated program references. When you call three.js/src/renderers/WebGLRenderer.js Lines 711 to 731 in 0f4df91
When a program is removed, keep in mind that it is not immediately removed from memory. That happens when the GC runs and we can't influence when the JS environment decides to run it. |
Hello @Mugen87, thank you for looking into this issue. I forced garbage collection (in memory profile tab its 5th icon, first is to take heap memory snapshot), but unfortunatelly it didnt garbage collectied it in next snapshot. What seems to be leaking is WebGLProgram from webgl context, a gpu resource, not the class wrapper which is called WebGLProgram too. To confirm this I renamed wrapper class to be sure. It looks like this WebGLProgram program instance reference is still somewhere and it is preventing garbage collection. I already spend few hours on this and I am more familiar with the issue, but I am not able to figure out this out yet. I also found some "similar" issue from that past. I am not sure if its related or not yet. |
It is not related, imo. Render states have no references to programs. |
I've checked the relevant code base again I don't think the root cause is on our side. Especially the behavior you have described here makes me think this is a browser related issue:
To me, this does not look like a memory leak. I suspect what we see is some sort of cashing mechanism of the browser to retain programs for a potential later use. Even if an app does not use a program for rendering anymore, it might be use it at a later point. Next to optimizations on engine levels, WebGL implementations apply optimizations as well to avoid unnecessary overhead. If the browser caching is implemented correctly, is a different question. But to be honest, if there is no ongoing growing memory allocation that eventually slows down the app or crashes the tab, I would not worry about 131 instances of |
I kind of agree with your conclusion. If I find some other reason or evidence I will report it. Also thanks for the link to chromium I will try to ask for advice / confirmation there. |
Description
WebGLPrograms are not correctly being disposed. I noticed this in my own project, but I can reproduce issue on official https://threejs.org/examples/#webgl_test_memory.
After each cycle of scene recreation (new mesh added / removed / disposed), there is extra +1 new WebGLProgram.
Number of instances seems to be capped at ~131 for my computer which is very strange.
Also then it seems like all above 131 will get deleted correctly which is even more weird.
Only way to correctly get rid of these additional instances is to recreate canvas which I know from my own project. (destroy and create new canvas). As an alternative it is possible to reuse the same instance of material to avoid this extra WebGLPrograms.
WebGLRenderer.info seems to show 1x Program, so either info or memory profiler is wrong.
Reproduction steps
I changed animate script to following:
function animate() {
setTimeout( animate, 1000 );
render();
}
Code
One present at https://threejs.org/examples/#webgl_test_memory
Live example
https://threejs.org/examples/#webgl_test_memory
Screenshots
Live (unmodified) webgl_test_memory screenshot 1
![image](https://private-user-images.githubusercontent.com/126272684/329877723-985d080a-5397-4123-bb08-28e9a0679afa.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk3OTE5MTcsIm5iZiI6MTczOTc5MTYxNywicGF0aCI6Ii8xMjYyNzI2ODQvMzI5ODc3NzIzLTk4NWQwODBhLTUzOTctNDEyMy1iYjA4LTI4ZTlhMDY3OWFmYS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjE3JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxN1QxMTI2NTdaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0xZTQwMzdjZmEzODU2ODg1NTdhOTA1ZTE0NzAxY2U5ZjJhNDhmYzFmNDNiNTIwOWUzZDkyNWI2MmUyNTFlNWM3JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.JHEl00TAe3ZK5O2um7Z6yg_lYw6cgMdnqOiA5od9Gqo)
Live (unmodified) webgl_test_memory screenshot 2
![image](https://private-user-images.githubusercontent.com/126272684/329877854-61e35840-4ee0-4e63-a549-b8c507e09cb2.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk3OTE5MTcsIm5iZiI6MTczOTc5MTYxNywicGF0aCI6Ii8xMjYyNzI2ODQvMzI5ODc3ODU0LTYxZTM1ODQwLTRlZTAtNGU2My1hNTQ5LWI4YzUwN2UwOWNiMi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjE3JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxN1QxMTI2NTdaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1hMTUxZWYwZTk0NGFlOWI5MGZlODYwYWEyZmY0ZDczM2Y0M2QxYTQ1ZTgxZDJhNGM4MDg2NWE2YjhiMTNkYjQxJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.1irsJPTCXtsWTZ45JSRsdYHR3nMmrETPmSR6fCp29AA)
Modified webgl_test_memory 1
![image](https://private-user-images.githubusercontent.com/126272684/329877297-5ae748e8-0f1b-4cb5-8ac5-3602cc64b3f5.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk3OTE5MTcsIm5iZiI6MTczOTc5MTYxNywicGF0aCI6Ii8xMjYyNzI2ODQvMzI5ODc3Mjk3LTVhZTc0OGU4LTBmMWItNGNiNS04YWM1LTM2MDJjYzY0YjNmNS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjE3JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxN1QxMTI2NTdaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0yM2U2OTZjNDIzNzhiYWMxODhjMTgxZDA1MGJmZjE0OTUxYmQ3NDE1MzllNjdjMzkzZmViMDk2MDc1ODRhNTEyJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.LW04r5ZsF443fp5ldeJWWRlaJKRsJYYEHv578euaM40)
Modified webgl_test_memory 2
![image](https://private-user-images.githubusercontent.com/126272684/329876624-7a9f777f-59b2-4f88-b78f-a6021517dfd2.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk3OTE5MTcsIm5iZiI6MTczOTc5MTYxNywicGF0aCI6Ii8xMjYyNzI2ODQvMzI5ODc2NjI0LTdhOWY3NzdmLTU5YjItNGY4OC1iNzhmLWE2MDIxNTE3ZGZkMi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjE3JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxN1QxMTI2NTdaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0zZmE5MGZkYjIzZmZmNThiM2MyZGYzZWRhZjRmMDIyZTg5YzA2NDk0OGRmMDJhNmFiZGFlNGExY2U5ODAxM2Q0JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.5MX2mCvj9645bb1qCLBWRWpH_v1TuWSE5EWDvPId9tI)
Version
i can reproduce on 159 and 164
Device
Desktop
Browser
Chrome version 124.0.6367.158 (Official Build) (64-bit)
OS
Windows
The text was updated successfully, but these errors were encountered: