【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();
}

  

 

上一篇:信号量的使用&生产者消费者问题


下一篇:SEO和SEM的区别与联系有哪些?SEM和SEO是什么?