Delete object in priority queue

Hi everyone,

I have a priority queue containing pointers of rectangle,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
void g_markCells(int qID)
{
  int ID = 0;
  priority_queue< gridRecord*, vector<gridRecord*>, CompareGridRecords > queue;
  gridRecord* gr = new gridRecord();
  gr->rec = new CRectangle();
  gr->rec->coverWholeSpace();
  gr->dist = 0;
  gr->isObject = false;
  gr->gridID=ID;
  ID++;
  queue.push(gr);
  while(!queue.empty())
  {
    gridRecord* curRecord = queue.top();
    queue.pop();
    if( !curRecord->rec->isCell() )
    {
      if( trimmedGrid(curRecord->rec, qID) )
      {
	gTrimmed++;
	continue;
      }
      else
      {
	for(int i=1; i <= 4; i++)
	{
	  gridRecord* childRecord = new gridRecord();
	  intersect++;
	  childRecord->rec = curRecord->rec->getChild(i);
	  childRecord->dist = childRecord->rec->getMinDist(queryTable[qID]->loc);
	  childRecord->gridID = ID;
	  ID++;
	  childRecord->isObject = false;
	  queue.push(childRecord);
	}
      }
    }

   while( !queue.empty() )
   {
     gridRecord* curRec = queue.top();
     queue.pop();
     delete curRec->rec;
     delete curRec;
   }
  delete gr->rec; 
  delete gr;
}


at the end, I have deleted the object pointer, however valgrind keeps telling me there is memory leak caused by new operator in this function.

This is the output of valgrind


==24573== 2,388 (24 direct, 2,364 indirect) bytes in 2 blocks are definitely lost in loss record 47 of 64
==24573==    at 0x402A6DC: operator new(unsigned int) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==24573==    by 0x806C92F: g_markCells(int) (in /home/hidayat/projects/32rrnn/bin/rrnn)
==24573==    by 0x806CD02: gridDynamic_RRNN() (in /home/hidayat/projects/32rrnn/bin/rrnn)
==24573==    by 0x804BCE2: main (in /home/hidayat/projects/32rrnn/bin/rrnn)


Would someone please tell me how to delete the object pointer in priority queue so that the memory leak gone? Thanks
Topic archived. No new replies allowed.