[Gc] CG and std::vector

Miguel Guinada miguel at trigenius.pt
Thu Jun 17 04:01:56 PDT 2004


Grettings,

Does the GC perform well deallocating memory inside an std::vector?

I have a std::vector wrapped in a (class something like this):

class Collection : public gc {
  …
}

class EntityVector : public Collection {
   vector<Entity *> entityVector; //NOTE: the class Entity inherits from
class gc 

   void cleanUp();
 public:
   void add(Entity *e)  {
     entityVector.push_back(e);
   }

   void remove(Entity *e);

   //etc.
}

When I destruct this class I execute cleanup:

void EntityVector::cleanUp() {
  vector<Entity *>::iterator it = entityVector.begin();

  for(; it != entityVector.end(); it++) {
    delete *it;
    *it = NULL;
  }
  entityVector.clear();
}
(I do the same for a single element when I call remove())



But it seams that GC is trying to delete a pointer that already was deleted
by my cleanup method and I get an AccessViolation! That or I'm doing
something wrong!

But if I don’t do my cleanup Borland’s Code Guard (memory profiling tool)
reports an resource leak! But I’m not sure that Code Guard is correct! Maybe
it reports the resource leak before GC does it’s job? 

I would like some advice on what to do! As well to ask if there is any tools
to monitor issues like this (I not getting along with CodeGuard)! 


Thanks very much!

Best Regards

Miguel Guinada

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.707 / Virus Database: 463 - Release Date: 15-06-2004
 



More information about the Gc mailing list