Skip to content
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

Memory leak in imshow #138

Open
AndreHat opened this issue Feb 7, 2018 · 4 comments
Open

Memory leak in imshow #138

AndreHat opened this issue Feb 7, 2018 · 4 comments

Comments

@AndreHat
Copy link

AndreHat commented Feb 7, 2018

I am using ImageView to display a video feed from a USB camera. After some time my RAM is completely full. After playing around with my code I realized it is the imshow(canvas["gui"]["canvas"], testimage) function that creates the leak. The speed at which my RAM fills are inversely proportional to the size of testimage, so the larger images did not affect me as bad. It doesn't seem as if any garbage collection happens and the memory just fills up till everything breaks.
Please try this sample code and tell me if you get the same result:

using ImageView
testimage = zeros(UInt8, 2, 2)
canvas = ImageView.imshow(testimage)
while (true)
    imshow(canvas["gui"]["canvas"], testimage)
end

Warning: On my computer this code fills 4GB RAM in less than 20 seconds, so stand ready to stop Julia before that happens.
I am Running this on Ubuntu 16.04 using Atom as an IDE.
Can anyone please tell me how to fix this?

@timholy
Copy link
Member

timholy commented Feb 7, 2018

Interesting. I can even comment out the function that does the real work,

diff --git a/src/ImageView.jl b/src/ImageView.jl
index 23637e8..a24f669 100644
--- a/src/ImageView.jl
+++ b/src/ImageView.jl
@@ -159,8 +159,9 @@ end
 
 function imshow(c::GtkReactive.Canvas, img::AbstractMatrix, anns=Signal(Dict{UInt,Any}());
                 kwargs...)
-    f = parent(widget(c))
-    imshow(f, c, img, default_clim(img), roi(img, default_axes(img))..., anns; kwargs...)
+    # f = parent(widget(c))
+    # imshow(f, c, img, default_clim(img), roi(img, default_axes(img))..., anns; kwargs...)
+    return nothing
 end
 
 function imshow(img::AbstractArray, clim;

and the memory still grows. However, if I also comment out the default anns argument, then the memory doesn't grow. It seems likely to be a Reactive bug, perhaps anns isn't being freed.

@timholy
Copy link
Member

timholy commented Feb 7, 2018

Yep, this does it too:

julia> using Reactive

julia> function silly(anns=Signal(Dict{UInt,Any}()); kwargs...)
           return nothing
       end
silly (generic function with 2 methods)

julia> while true
           silly()
       end

@timholy
Copy link
Member

timholy commented Feb 7, 2018

x-ref JuliaGizmos/Reactive.jl#173

@Affie
Copy link

Affie commented Jul 24, 2018

@AndreHat, a possible solution to your problem is to use the (unexported) ImageView.imshow! function. You can modify your code to replace imshow as follows:

ImageView.imshow!(canvas["gui"]["canvas"], testimage,  canvas["annotations"])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants