Problem with object scope...?
I was given a project that has DialogClassA, DialogClassB, and DataClass1 and they're setup like this. DialogClassA's ctor uses "new" to instantiates an obj of DialogClassB (even though it's not visible yet), and DialogClassB's ctor instantiates an obj of DataClass1 via "new" too. ( DataClass1 holds the data object for the dialog from DialogClassB).
The user hits a button on DialogClassA to bring up a Dialog of type DialogClassB and manipulate & save data and exit.
Problem: the DataClass1 obj is not destroyed when DialogClassB closes and remains around until DialogClassA's dctor kills DialogClassB and DialogClassB's dctor calls DataClass1's dctor. When the user re-opens the DialogClassB it still has the old data in it from the last time the user had it opened. Should I:
1) only create a DataClass1 object when the user Opens up the DialogClassB and does a File->New or File->Open, then destroy it when DialogB closes? (haven't gotten this to work yet)
2)...ah, something else.
It's seems terribly inefficient to have an object of DataClass1 hang around until the entire application closes just because of the way the "new"s and "delete"s were set up by someone in the ctors & dctors. I don't have a ton of experience in this but what do you think?
Thanks.....