Git Product home page Git Product logo

Comments (6)

mitsuhiko avatar mitsuhiko commented on June 27, 2024 1

The linked fix is not capable of fully solving this. It's just a WIP now for me to make some progress on what the actual issue is. I know now what the problem is, but I don't have a particularly nice looking solution yet.

from minijinja.

mitsuhiko avatar mitsuhiko commented on June 27, 2024

What is likely happening here is that the closure sets up a circular reference. This needs some sort of support to capture these weakly instead. I did not check yet but I believe the Arc that is not freed is this one:

let closure = stack.pop();

The closure there holds the hello object which is the one we leak.

from minijinja.

mitsuhiko avatar mitsuhiko commented on June 27, 2024

Specifically the problem is this. When a macro is defined it stores a closure object on the context. From then on every StoreLocal also persists the value on the closure. This way a macro gains a reference to itself via the closure and a cycle is created.

from minijinja.

sandhose avatar sandhose commented on June 27, 2024

Trying out the PR branch, it looks like macros are still leaking memory for me. I'm on macOS and struggling a bit with Instruments to do those profiles, because for some reasons the minijinja-related symbols in stack traces don't have the source file information, so I'm trying to guess out of the allocation stack traces… But it still looks like Vm::build_macro (and in particular the Value::from_object call) is the one leaking memory. How can I help you best to debug those leaks?

from minijinja.

sandhose avatar sandhose commented on June 27, 2024

Commenting out the store of the caller in the context (those three lines) does cut the leak in half, so there is probably a cycle here. I'm not using the caller so I could test it in my app ; in my profiles it cuts from 28MiB to 11MiB for 250 renders.

from minijinja.

mitsuhiko avatar mitsuhiko commented on June 27, 2024

One solution might be to keep track of all created closures across an entire render call and to then break the cycles at the end. For render_to_state this cleanup would need to be deferred until the state is dropped.

from minijinja.

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.