Hi,
Please go through the below code.
Code:
class PlotDraw
{
public :
Graphics::TBitmap *DrawnBitmap;
PlotDraw(TComponent *Owner);
~PlotDraw();
Initialise();
Drawing(TObject *Sender);
};
PlotDraw::PlotDraw(TComponent *Owner)
{
Initialise();
}
PlotDraw::~PlotDraw()
{
delete DrawnBitmap;
}
PlotDraw::Initialise()
{
DrawnBitmap = new Graphics::TBitmap;
// Other initialisation code
}
// method calls with the various events
PlotDraw::Drawing(TObject *Sender)
{
delete DrawnBitmap;
Initialse();
}
In the above, method Drawing() calls on when an event trigger.
Every time it deletes the memory (data) and allocate "new" memory in Initialisation() method.
What will happen, If I don't delete the allocated memory before calling Initialise() in Drawing() method ?
Is it a good idea to delete the memory and re allocate with a new operator?
Thanks in advance.