i think you have a few misconceptions about garbage collection in c++, free should only be used if you used malloc to allocate memory. Likewise delete should only be used if you used new to allocate.
class myClass
{
public:
int my_i;
char my_ch;
double my_d;
std::string * my_str;
myClass();
~myClass();
};
myClass::myClass()
{
my_str = new std::string("this is a string");
}
myClass::~myClass()
{
delete my_str; //this is the only member that has to be explicitly deleted
}
So for example let's say the main() function creates a myClass object like so:
1 2 3 4 5 6
myClass * mc_ptr;
mc_ptr = new myClass();
//do some stuff here
delete mc_ptr;
when i call delete mc_ptr; the destructor for myClass is called. this deletes the string that is allocated when the constructor was called. the other variables (my_i, my_ch, my_d) are automatically deallocated at this time.