Game Development Community

FreeListChunker potential bug??

by Lateral Punk · in Torque Game Engine · 06/02/2006 (10:20 pm) · 2 replies

Iin FreeListChunker::freeBlocks() should we set numAllocated to zero as such:
// Allow people to free all their memory if they want.
   void freeBlocks()
   {
      DataChunker::freeBlocks();


      numAllocated = 0;  //Lateral Punk: insert this line

      // We have to terminate the freelist as well or else we'll run
      // into crazy unused memory.
      freeListHead = NULL;
   }


??

#1
06/06/2006 (10:18 am)
Anyone? I do think this is a bug, the missing line could cause hiccups :)
#2
06/06/2006 (4:03 pm)
Well, it IS a bug, but it's completely harmless. The only problem is that the if-block in function free():
// If nothing's allocated, clean up!
      if(!numAllocated)
      {
         freeBlocks();
         freeListHead = NULL;
      }
will never be executed ever again. That is not a real problem because there is no memory leak, the blocks are simply freed later than expected (in the class destructor, to be precise). In my humble opinion, that if-block should not even be present in the first place, because I usually do NOT want to clean up all my blocks even if I freed all of them, because I may need them right away. So if I had to change the class, I will remove the if-block entirely and therefore remove also the useless data member numAllocated.