title: Avoid Qpainter memory leak
body: <p>I'm facing a memory leak problem using QPainter on a QPixmap. I need to set about 250000 points around earth, on a map (nav points). Each of them share the same icon but have a specific label. I add all these points to the same layer.</p>
  
  <p>Here is my code :</p>
  
  <pre><code>void Gspv::addFixes() // waypoints layer
  {
      waypoints = new GeometryLayer("Waypoints", mapadapter);
      mc-&gt;addLayer(waypoints);
  
      //Icon
      QPixmap icone(38,38);
      icone.fill(Qt::transparent);
      QPainter *paint = new QPainter(&amp;icone);
      paint-&gt;setRenderHint(QPainter::Antialiasing);
      paint-&gt;setBrush(Qt::cyan);
      paint-&gt;setPen(Qt::black);
      static const QPoint triangle[3] = {
          QPoint(15,0),
          QPoint(3, 20),
          QPoint(27,20)
      };
      paint-&gt;drawPolygon(triangle, 3);
      delete paint;
  
      //Check file
      QFile file(QCoreApplication::applicationDirPath() + "/data/Waypoints.txt");
      if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
          QMessageBox::information(0, "erreur lecture fichier : " + file.fileName(), file.errorString());
          return;
      }
  
      //Parsing file
      QTextStream in(&amp;file);
      while(!in.atEnd()) {
          QString line = in.readLine();
          QStringList fields = line.split(",");
          QString str = fields.at(1);
          double latitude = str.toDouble();
          str = fields.at(2);
          double longitude = str.toDouble();
          str = fields.at(0);
  
          addCode(icone,str); // Prob here
  
          //Add current point to layer
          Point* pointCourant = new Point(longitude, latitude, icone, str);
          pointCourant-&gt;setBaselevel(10);
          pointCourant-&gt;setMaxsize(QSize(38, 38));
          waypoints-&gt;addGeometry(pointCourant);
  
      }
  
      file.close();
  }
  
  
  //Add code to QPixmap
  void Gspv::addCode(QPixmap &amp;pm, QString &amp;code)
  {
      QPainter pmp(&amp;pm);
      pmp.setPen(Qt::black);
      pmp.setFont(QFont("ArialBold",9));
      pmp.eraseRect(0,20,38,15);
      pmp.drawText(0,32,code);
  }
  </code></pre>
  
  <p>Everything works as expected, except that it causes severe memory leaks.
  Problem is when adding the code within the while loop. Whatever I do (addcode in the addfixes method or in a specific one as it is with addCode), I get a memory leak.</p>
  
  <p>Even if the code is only reduced to :</p>
  
  <pre><code>void Gspv::addCode(QPixmap &amp;pm, QString &amp;code)
  {
      QPainter pmp(&amp;pm);
      // here it does nothing !
  }
  </code></pre>
  
  <p>the memory leak is. And no matter whether the statement is static or dynamic, the result is the same.</p>
  
  <p>Without the addition of the code, the memory usage is about 152 Mo, which is low enough. With the addition of this simple code, it bugs out of memory.</p>
  
  <p>I have read many posts on the QPainter and the memory leak, but I can't handle it.</p>
  
  <p>Will you have an help for that ?</p>
  
  <p>Thanks in advance.</p>