【问题标题】:how to clear +(UIImage *) from memory如何从内存中清除 +(UIImage *)
【发布时间】:2019-05-08 17:01:51
【问题描述】:

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

+(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'; 但是,我无法调用该函数。

【问题讨论】:

  • 你为什么认为这些对象不会自行清理?
  • 它会自动清理吗?我正在使用 Xcode 调试和仪器调试代码。随着时间的推移,CPU 使用率和手机温度似乎迅速上升。
  • 那是 Objective-C
  • 您已经发布了 Objective-C 代码。为什么你的问题上有swift 标签?

标签: ios objective-c opencv


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2017-03-11
    • 1970-01-01
    • 2012-01-20
    • 1970-01-01
    • 1970-01-01
    • 2015-11-21
    • 2011-05-10
    • 2015-11-21
    • 1970-01-01
    相关资源
    最近更新 更多