I enabled heap debugging because of a memory leak error I started seeing in somebody else's code and I pinned down the problem (at least, so I think) to the destructor of a class, right after the call to the delete []
below.
MyClass::~MyClass() {
delete [] my_class_member_;
}
Now I confirmed that my_class_member_ which is an array of pointers to objects of a struct, say, MyStruct
, has been allocated property using new []
so I am not sure what is causing this leak? Here's what the new []
call looks like:
delete [] my_class_member_;
my_class_member_ = new MyStruct[somesize_];
Next, the struct MyStruct
is also relatively simple and is as follows (stripped down):
struct MyStruct {
MyStruct() {}
~MyStruct() {
for( PtrList<PClass>::iterator it(ps); it.more(); it.next() ) {
delete it.cur();
}
for( PtrList<RClass>::iterator it(rs); it.more(); it.next() ) {
delete it.cur();
}
delete shift;
}
PtrList<PClass> ps;
PtrList<RClass> rs;
};
Now PtrList
is a list of pointers (a built-in type of the application devkit we're using).. I am pretty certain that can't be at fault. Anyways, is anything out of whack that anybody notices here?? Appreciate any insight..