OpenCV的图像处理程序,利用多线程加速,在调用async函数造成内存泄露

核心函数为anync_res
async_res[i] = std::async(std::launch::async,
this, image, &peak_value, &res, &scaleselect, i->int
{
res[i] = detect(_tmpl, getFeatures(image, 0, scaleselect[i]), peak_value[i]);
return i;
});
其中调用的detect函数,在单线程逐个跑的时候,没有内存泄露问题。采用如上方式调用,会出现内存一直增长的问题。

            async_res()函数的上下文如下:
            ...
    else
{
    float scaleselect[3] = { 1.0f, 1.0f / scale_step, scale_step };
    float peak_value[3];
    cv::Point2f res[3];
    std::vector<std::future<int>> async_res(3);
    for (int i = 0; i < 3; i++)
    {
        async_res[i] = std::async(std::launch::async,
            [this, image, &peak_value, &res, &scaleselect, i]()->int
        {
            res[i] = detect(_tmpl, getFeatures(image, 0, scaleselect[i]), peak_value[i]);
            return i;
        });
    }
    float max_peak_value = -1;
    cv::Point2f bestres;
    for (int i = 0; i < 3; i++)
    {
        async_res[i].wait();
        if (scale_weight*peak_value[i] > max_peak_value)
        {
            max_peak_value = peak_value[i];
            bestres = res[i];
            _scale = _scale*scaleselect[i];
            _roi.width = _roi.width*scaleselect[i];
            _roi.height = _roi.height*scaleselect[i];
        }
    }
    内存定位的地方肯定是没问题。但是原因由于水平有限,查不到根本原因。希望有大神可以指点一二,或者详细说明一下排查思路。非常感谢!

是否是线程已经断了,但是vector没有清理出去?
std::vectorstd::future<int> async_res(3);

获取 ROI 时没有 clone引发的内存泄漏,保险的用法就是在任何时刻都加上 clone().