Giter Club home page Giter Club logo

Comments (3)

szabolcsdombi avatar szabolcsdombi commented on June 28, 2024

Hi, as I remember we do not rely on __del__ for resource handling. we have a .realease() method in most cases.
We also have some stress test in the utils. I get back with a more detailed answer when my time allows it.

from moderngl.

abey79 avatar abey79 commented on June 28, 2024

Right. My including of del ctx is pointless anyway, as it as not additional effect since ctx is reassigned.

Adding ctx.release() solves the issue:

import moderngl

for i in range(1000):
    if (i % 50) == 0:
        print(f"iteration {i}")
    ctx = moderngl.create_context(standalone=True)
    ctx.release()

Output:

iteration 0
iteration 50
iteration 100
iteration 150
iteration 200
iteration 250
iteration 300
iteration 350
iteration 400
iteration 450
iteration 500
iteration 550
iteration 600
iteration 650
iteration 700
iteration 750
iteration 800
iteration 850
iteration 900
iteration 950

I'll let you close the issue unless you feel there is something to be done still, may be a note in the docs?

from moderngl.

szabolcsdombi avatar szabolcsdombi commented on June 28, 2024

Related docs page: manually-releasing-objects

Some notes that pop into my mind:

  • We do not use __del__ due to it is not reliable and it can be entirely prevented with a dangling ref to the object. The simplest I can think of is storing context in it's extra field.

  • Most of the ModernGL objects hold a ref to the context mostly to have access to the gl calls. Without properly implementing tp_traverse the GC won't find the island of dead objects just by loosing all the refs from the main code.

  • __del__ might be called without having an active gl context making a fault when calling opengl functions.

  • some objects cannot be released, for example when the OpenGL context was lost or destroyed by the window.

from moderngl.

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.