zoukankan      html  css  js  c++  java
  • 【c++基础】出现内存泄漏的一段代码

    前言

    code

    float* lanemap = new float[output_h * output_w];
    float* fsmap = new float[output_h * output_w];
    cv::Mat showimg;
    std::vector<PointProp> border_points;
    CAN can_fs;
    can_fs.canInit();
    while(true)
    {
      sem_wait(&sem_signal);
      mtx.lock();
      if(lane_maps.size()>0
        && fs_maps.size()>0
        && showimgs.size()>0
        && points_queue.size()>0)
      {
         memcpy(lanemap, lane_maps[0], output_h * output_w * sizeof(float));
         memcpy( fsmap, fs_maps[0], output_h * output_w * sizeof(float));
         showimg = showimgs.front();
         border_points = points_queue.front();
         lane_maps.erase( lane_maps.begin()); // pop_back();
         fs_maps.erase( fs_maps.begin()); // pop_back();
         showimgs.erase( showimgs.begin()); // pop_back();
         points_queue.erase(points_queue.begin()); // pop_back();
         lane_maps.shrink_to_fit();
         fs_maps.shrink_to_fit();
         showimgs.shrink_to_fit();
         points_queue.shrink_to_fit();
         mtx.unlock();
         sem_post(&sem_signal);
      }
      else
      {
        mtx.unlock();
        sem_post(&sem_signal);
        memset(lanemap, 0, output_h * output_w *sizeof(float));
        memset( fsmap, 0, output_h * output_w *sizeof(float));
        std::vector<PointProp>().swap(border_points);
        showimg.release();
        continue;
      }
      s = timeNow();
      can_fs.canData(border_points);
      can_fs.canSendFs();
      showSegMap(showimg, lanemap, fsmap, border_points);
      memset(lanemap, 0, output_h * output_w *sizeof(float));
      memset( fsmap, 0, output_h * output_w *sizeof(float));
      std::vector<PointProp>().swap(border_points);
      showimg.release();
    }
    

      

  • 相关阅读:
    场景法设计测试用例
    编写边界条件测试用例原则
    CSS
    JavaScript
    HTML
    lamp安装教程
    Linux(lamp安装)
    oracle sqlplus常用命令
    利用同步器实现互斥锁
    工厂模式--简单工厂模式
  • 原文地址:https://www.cnblogs.com/happyamyhope/p/14040753.html
Copyright © 2011-2022 走看看