delete objects

Hi.
I monitor memory usage with windows task manager.

After statement:

VisualShape* object = new BlockArrive();

memory usage by this process raises for about 100 KB.

I have tried to delete these object with

delete object;

and

object->~VisualShape();

but memory usage doesn't fall.

How to delete object from memory ?
Don't worry about it. The program don't always give memory back to the OS because it might need that memory later anyway. 100 KB isn't much memory. Try allocate and free a much larger object and you might get the behaviour you expected.
I have more graphic objects and I connect these objects with wires.
So when I allocate 100 objects, it's more than 15 mb.. And when I delete them, it still 15 mb..

Make sure ~VisualShape() is virtual.
It is virtual (in base graphic class)..

virtual ~VisualShape()
{
}

Do I need to put some code here ?
¿Do you need to release resources?

You shouldn't call the destructor directly, just use delete
I don't call destructor..

I just tried to call it once but i saw that didn't help..:-)

1
2
3
4
5
6
7
8
9
void ComplexVisualShape::ReleaseAll()
{
    list<VisualShape*>::iterator iter;
    for (iter = _visualElements.begin(); iter != _visualElements.end(); iter++)
    {
        delete (*iter);
    }
    _visualElements.clear();
}
Can somebody confirm that this is the right way to delete object and free memory ?

1
2
3
4
5
6
7
8
9
void ComplexVisualShape::ReleaseAll()
{
    list<VisualShape*>::iterator iter;
    for (iter = _visualElements.begin(); iter != _visualElements.end(); iter++)
    {
        delete (*iter);
    }
    _visualElements.clear();
}
When unsure, add printing. Answer is: looks fine to me.
http://ideone.com/lDU8B
Maybe class VisualShape has data that it doesn't free?
Topic archived. No new replies allowed.