首页 > 解决方案 > 如何从内存中清除 +(UIImage *)

问题描述

是否可以清除以下示例代码的内存?

+(UIImage *) makeGray:(UIImage *) image {
     // Transform UIImage to cv::Mat
    cv::Mat imageMat;
    UIImageToMat(image, imageMat);

    //Transform image to grayscale
    cv::Mat grayMat;
    cv::cvtColor(imageMat, grayMat, CV_BGR2GRAY);

    //draw contour
    if(shape[i].size() >0 && ....)
    {
     drawContours(....)

      //get largest contour
       if(a > largetest_area)
      {
        largest_area = a;
        largest_contour_index = i;
        bounding_rect = boundingRect(contours[i]);
        largest_contour_value = boundingRect(contours[largetst_contour_index])

    return MatToUIImage(grayMat);
}

我试过grayMat.release()没有成功。看起来我可以delete[] 'function name';但是,我无法调用该函数。

标签: iosobjective-copencv

解决方案


内存问题不会显示为 CPU 使用率。使用带有“Leaks”模板的 Instruments.app 来查找内存问题,并使用“Profiler”来查找性能问题。


推荐阅读