Code Monkey home page Code Monkey logo

Comments (5)

Mugen87 avatar Mugen87 commented on June 9, 2024

I have debugged the example and it seems the internal program cache does not retain outdated program references. When you call material.dispose(), the renderer checks if an instance of WebGLProgram is still required and if not, releases it and removes internal references. The code that triggers these operations is:

function releaseMaterialProgramReferences( material ) {
const programs = properties.get( material ).programs;
if ( programs !== undefined ) {
programs.forEach( function ( program ) {
programCache.releaseProgram( program );
} );
if ( material.isShaderMaterial ) {
programCache.releaseShaderCache( material );
}
}
}

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.

from three.js.

A2H2 avatar A2H2 commented on June 9, 2024

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.
#19645

from three.js.

Mugen87 avatar Mugen87 commented on June 9, 2024

I also found some "similar" issue from that past. I am not sure if its related or not yet.
#19645

It is not related, imo. Render states have no references to programs.

from three.js.

Mugen87 avatar Mugen87 commented on June 9, 2024

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:

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.

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 WebGLProgram retained somewhere in memory. If you insist to report it, do it here: https://issues.chromium.org/issues.

from three.js.

A2H2 avatar A2H2 commented on June 9, 2024

I kind of agree with your conclusion. If I find some other reason or evidence I will report it.
I tried several code changes to get rid of those WebGLPrograms but I was unable to achieve it.

Also thanks for the link to chromium I will try to ask for advice / confirmation there.

from three.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.