Giter Club home page Giter Club logo

Comments (15)

Gnimuc avatar Gnimuc commented on July 24, 2024 1

Thanks for reporting the issue! I've just tagged a new version which should be released within a hour.

from cimgui.jl.

Gnimuc avatar Gnimuc commented on July 24, 2024

Which example?

from cimgui.jl.

sairus7 avatar sairus7 commented on July 24, 2024

Confirm memory leak at Windows 10, both from demo/demo.jl and examples/demo.jl.

from cimgui.jl.

sairus7 avatar sairus7 commented on July 24, 2024

Looks like I didn't notice this leak in this PR, since there is very slow operating memory increase of Julia process. This bug also present in this ImPlot branch.

Looked at both demo.jl code but I have no idea why it happens, maybe because I just commented glfwSetErrorCallback (didn't know what argument it takes) or misused ImGuiGLFWBackend.create_context and ImGuiOpenGLBackend.create_context functions, or there are deeper issues with newly generated code? @Gnimuc can you take a look at this?

from cimgui.jl.

Gnimuc avatar Gnimuc commented on July 24, 2024

only on Windows? does the problem persist if you disable the docking and multi-viewport features?

from cimgui.jl.

Gnimuc avatar Gnimuc commented on July 24, 2024

The leak is probably due to this line in the backend: https://github.com/JuliaImGui/ImGuiGLFWBackend.jl/blob/a005da40908b1d5b1335762ef0723bae570453f8/src/interface.jl#L207

The implementation assumes the C-managed Ptr{ImGuiPlatformMonitor} pointer is initilized as a C_NULL, so there is no need to manually free it on the Julia side before we fill up it with the new resources. I've checked the related IMGUI code before, but I might be wrong as well.

from cimgui.jl.

sairus7 avatar sairus7 commented on July 24, 2024

I'm not sure if I understand you corectly, do you mean that monitors_ptr ownership is passed to platform_io object that is gc'ed by C library?

from cimgui.jl.

Gnimuc avatar Gnimuc commented on July 24, 2024

Not gc-ed, but free-ed by C/C++. As platform_io is an object managed by the C/C++ library, I guess the C++ code does something like:

if (platform_io.monitors_ptr)
    delete[] platform_io.monitors_ptr

This is why I allocated monitors_ptr through Libc.malloc.

from cimgui.jl.

sairus7 avatar sairus7 commented on July 24, 2024

But this is called only once - how can it cause constant memory increase inside rendering cycle?

Can it be somehow related to this bug with arrays or pointers? wsphillips/ImPlot.jl#23

from cimgui.jl.

Gnimuc avatar Gnimuc commented on July 24, 2024

By memory leak, do you mean "memory constantly increasing when running the GUI window" or "memory is not released correctly after GUI window is closed". I would like to know whether the leak is on the C side or the Julia side. A MWE example would be helpful here.

from cimgui.jl.

sairus7 avatar sairus7 commented on July 24, 2024

I mean, memory constantly increasing when running the GUI window.
It repeats with most examples, lets take short one from ImGuiGLFWBackend readme, just an empty window with no widgets, no multiport or docking. It starts with 360 MB of RAM and after 1 minute grows up to 1017 MB. (~11MB/sec).

using ImGuiGLFWBackend
using ImGuiGLFWBackend.LibCImGui
using ImGuiGLFWBackend.LibGLFW
using ImGuiOpenGLBackend
using ImGuiOpenGLBackend.ModernGL

# create contexts
imgui_ctx = igCreateContext(C_NULL)

window_ctx = ImGuiGLFWBackend.create_context()
window = ImGuiGLFWBackend.get_window(window_ctx)

gl_ctx = ImGuiOpenGLBackend.create_context()

# enable docking and multi-viewport
# io = igGetIO()
# io.ConfigFlags = unsafe_load(io.ConfigFlags) | ImGuiConfigFlags_DockingEnable
# io.ConfigFlags = unsafe_load(io.ConfigFlags) | ImGuiConfigFlags_ViewportsEnable

# set style
igStyleColorsDark(C_NULL)

# init
ImGuiGLFWBackend.init(window_ctx)
ImGuiOpenGLBackend.init(gl_ctx)

try
    while glfwWindowShouldClose(window) == GLFW_FALSE
        glfwPollEvents()
        # new frame
        ImGuiOpenGLBackend.new_frame(gl_ctx)
        ImGuiGLFWBackend.new_frame(window_ctx)
        igNewFrame()

        # UIs
        # igShowDemoWindow(Ref(true))
        # igShowMetricsWindow(Ref(true))

        # rendering
        igRender()
        glfwMakeContextCurrent(window)
        w_ref, h_ref = Ref{Cint}(0), Ref{Cint}(0)
        glfwGetFramebufferSize(window, w_ref, h_ref)
        display_w, display_h = w_ref[], h_ref[]
        glViewport(0, 0, display_w, display_h)
        glClearColor(0.45, 0.55, 0.60, 1.00)
        glClear(GL_COLOR_BUFFER_BIT)
        ImGuiOpenGLBackend.render(gl_ctx)

        # if unsafe_load(igGetIO().ConfigFlags) & ImGuiConfigFlags_ViewportsEnable == ImGuiConfigFlags_ViewportsEnable
        #     backup_current_context = glfwGetCurrentContext()
        #     igUpdatePlatformWindows()
        #     GC.@preserve gl_ctx igRenderPlatformWindowsDefault(C_NULL, pointer_from_objref(gl_ctx))
        #     glfwMakeContextCurrent(backup_current_context)
        # end

        glfwSwapBuffers(window)
    end
catch e
    @error "Error in renderloop!" exception=e
    Base.show_backtrace(stderr, catch_backtrace())
finally
    ImGuiOpenGLBackend.shutdown(gl_ctx)
    ImGuiGLFWBackend.shutdown(window_ctx)
    igDestroyContext(imgui_ctx)
    glfwDestroyWindow(window)
end

from cimgui.jl.

Gnimuc avatar Gnimuc commented on July 24, 2024

Thanks for the example! I can reproduce it on my machine as well. Trying to looking into it...

from cimgui.jl.

sairus7 avatar sairus7 commented on July 24, 2024

Some effects:

  • Without any windows open, memory increase in 1 minute: 270 MB -- 922 MB (~11 MB/sec).
  • With some window (demo or metrics), memory increase in 1 minute: 270 MB -- 1180 MB (~15 MB/sec).
  • Repeated runs of this script from the same Julia console increases initial GUI process memory.

from cimgui.jl.

sairus7 avatar sairus7 commented on July 24, 2024

I've tried the same example with dev ImGuiOpenGLBackend, and now it is not growing in memory but produces a bunch of the following errors from time to time:

┌ Error: GLFW ERROR: code 65544 msg: WGL: Failed to make context current: The handle is invalid.
└ @ ImGuiGLFWBackend C:\Users\user\.julia\packages\ImGuiGLFWBackend\42XtF\src\callbacks.jl:2
┌ Error: GLFW ERROR: code 65544 msg: WGL: Failed to make context current: The requested transformation operation is not supported.
└ @ ImGuiGLFWBackend C:\Users\user\.julia\packages\ImGuiGLFWBackend\42XtF\src\callbacks.jl:2

from cimgui.jl.

Gnimuc avatar Gnimuc commented on July 24, 2024

I can not reproduce that on macOS, feel free to file a new issue.

Does this happen without the new patch? If so, you could apply the patch right above this line:

https://github.com/JuliaImGui/ImGuiOpenGLBackend.jl/blob/master/src/device.jl#L114

from cimgui.jl.

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.