Skip to content

CUDA ORB memory leak #3994

@incubus-ank

Description

@incubus-ank

I suspect a memory leak in the ORB's function when it doesn't find key points.

Minimal code example

#include <iostream>
#include <opencv2/cudafeatures2d.hpp>
#include <opencv2/opencv.hpp>
#include <thread>

int main() {
    cv::cuda::GpuMat gpu_image(1536, 2048, CV_8UC1, cv::Scalar(0));

    for (int i = 0; i < 10000; ++i) {
        cv::Ptr<cv::cuda::ORB> detector = cv::cuda::ORB::create();

        cv::cuda::GpuMat keypoints;
        cv::cuda::GpuMat descriptors;
        cv::cuda::Stream stream;

        detector->detectAndComputeAsync(gpu_image, cv::noArray(), keypoints, descriptors, false, stream);

        stream.waitForCompletion();

        if (i % 1000 == 0) {
            std::cout << i / 1000 << " " << keypoints.size() << std::endl;
        }

        keypoints.release();
        descriptors.release();
        detector->clear();

        std::this_thread::sleep_for(std::chrono::milliseconds(10));
    }
    return 0;
}

Massif result

--------------------------------------------------------------------------------
Command:            ./my_app
Massif arguments:   (none)
ms_print arguments: massif.out.26554
--------------------------------------------------------------------------------


    MB
129.9^                                                                       #
     |                                                                   @@::#
     |                                                               @::@@ : #
     |                                                          :::::@: @@ : #
     |                                                    ::@@:::: : @: @@ : #
     |                                               :@@:@: @@: :: : @: @@ : #
     |                                          ::::::@ :@: @@: :: : @: @@ : #
     |                                     ::@@:: : ::@ :@: @@: :: : @: @@ : #
     |                               @:::::: @ :: : ::@ :@: @@: :: : @: @@ : #
     |                           :@@:@: :::: @ :: : ::@ :@: @@: :: : @: @@ : #
     |                      @@::::@ :@: :::: @ :: : ::@ :@: @@: :: : @: @@ : #
     |                  :@@@@ : ::@ :@: :::: @ :: : ::@ :@: @@: :: : @: @@ : #
     |             ::@:::@@ @ : ::@ :@: :::: @ :: : ::@ :@: @@: :: : @: @@ : #
     |        :::@@: @: :@@ @ : ::@ :@: :::: @ :: : ::@ :@: @@: :: : @: @@ : #
     |   @@:@@:::@ : @: :@@ @ : ::@ :@: :::: @ :: : ::@ :@: @@: :: : @: @@ : #
     | ::@ :@ :::@ : @: :@@ @ : ::@ :@: :::: @ :: : ::@ :@: @@: :: : @: @@ : #
     | : @ :@ :::@ : @: :@@ @ : ::@ :@: :::: @ :: : ::@ :@: @@: :: : @: @@ : #
     | : @ :@ :::@ : @: :@@ @ : ::@ :@: :::: @ :: : ::@ :@: @@: :: : @: @@ : #
     | : @ :@ :::@ : @: :@@ @ : ::@ :@: :::: @ :: : ::@ :@: @@: :: : @: @@ : #
     | : @ :@ :::@ : @: :@@ @ : ::@ :@: :::: @ :: : ::@ :@: @@: :: : @: @@ : #
   0 +----------------------------------------------------------------------->Gi
     0                                                                   22.31

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions