I have a class:
class A {
A();
////////something about the class A
};
then I have another class:
class B {
public:
B();
A* member_a;
};
B::B()
{
this->member_a = new A();
}
what I want to do is like this:
main()
{
vector<B> vec_b;
int num=1;
while(some_condition)
{
for (int i=0; i<num; i++)
{
vec_b.pushback(B());
}
////////do something about vec_b;
num++;
}
}
I know I am facing a memory leak issue because of the new A()
in the constructor of class B
. So I am trying to get help to release the memory after each while
loop, which means to recycle all the memory that has been taken by the vec_b
and all the objects of class B in the vector, the most important is to release the memory taken by class-A-objects.
Thank you very much!