Skip to content

Memory leak like situation in Julia Bindings #2766

Open
@archit120

Description

@archit120
System information (version)
  • OpenCV => 4.4
  • Operating System / Platform => Ubuntu 18.04
  • Compiler => G++
Detailed description

Tracking issue based on question at https://stackoverflow.com/questions/64978891/how-do-i-fix-a-julia-opencv-cxx-memory-leak-in-image-capturing

A memory leak-like situation can happen in the Julia bindings as the Julia garbage collector is not aware of the actual size of the objects allocated by OpenCV. When the GC does run, objects are freed properly so the only problem is that GC does not run automatically when needed. A temporary fix is to force GC run when necessary using GC.gc()

Steps to reproduce

The following Julia code can cause garbage to keep getting accumulated till the loop ends at which point all the memory is freed at once. A temporary fix is to call GC.gc() inside the loop.

using OpenCV
using Printf
cv = OpenCV

function main( )
    vidDevice="/dev/video0"
    cap = cv.VideoCapture(vidDevice)
    count = 1000
    while (cv.isOpened(cap) && count > 0)
        @printf("Capturing %4d\r", count)
        ret,img = cv.read(cap)
        count = count - 1
        
    end
    cv.release(cap)
    cv.destroyAllWindows()

end

main()
Issue submission checklist
  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues,
    answers.opencv.org, Stack Overflow, etc and have not found solution
  • I updated to latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions