c++ - Destroy an object with variables (free memory) -
i trying create event/date organizer in c++. overview calender show 1 month , every day in calender object (type: eventcell) class eventcell stores events day in vector (name: eventdata type: "eventinfo": class storing day, name, start/endtime).
but when switch month want clear vector, destroy of objects , free memory of variables. tried this:
for (unsigned int = 0; < termindata.size(); i++) { delete termindata[i]; } termindata.clear();
it calls deconstructor variables etc still alive. if make example:
termindata[0]->getday(); result: 3
i still value of variable deleted object...
i think if don't delete gets big, because every time change month, creating object every event.
any suggestions how delete object variable etc memory , create new?
i still value of variable deleted object...
no, garbage value. accessing termindata[0]
after termindata.clear();
you've invoked undefined behaviour.
any suggestions how delete object variable etc memory , create new?
you've deleted objects successfully. create new objects, construct them did originals. memory of old objects free used other objects.
Comments
Post a Comment