Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to best free up DNN and GPU resources when finished?

A little bit of context first...I'm using OpenCV 4.2 which I've compiled from source and enabled CUDA support along with the Java bindings. I'm currently running on a Windows 10 PC (Intel Core i7-9700 with 8 cores) and using a Nvida Geforce RTX 2080 (has 16 GB of GPU memory, 8 GB dedicated memory and 8 GB of shared memory). We have an existing Java application and so have been using the Java bindings to access OpenCV. With that setup, I'm able to get 30 FPS while running a Yolo object detection against a live, streaming video with no problem. So that part is working out great.

The problem I'm having is how to best free up GPU memory when done processing a video. Each time I startup a video it uses about 1 GB of the dedicated GPU memory. When the video is done but my process is still running it's not freeing up the 1 GB of used GPU memory per the Windows task manager. It's not until I stop the application that all of the GPU memory is freed up. The actual Java application, when finished processing a video, is using less than 25 MB of system memory. I don't see any methods on the "org.opencv.dnn.Net" object to free up resources when done. It might be a memory issue in our Java application that I'll continue to troubleshoot but I'm nulling out all of the references to objects when finished with a video. The came to light when I started to get "GPU out of memory" errors after starting and stopping a video several times within the application. I'm looking for any suggestions on how best to free up DNN and GPU resources when finished.

Let me know if there's any additional information that would be helpful.

Thanks, Dave