delete objects

Jun 16, 2012 at 1:19pm
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 ?
Jun 16, 2012 at 1:57pm
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.
Jun 16, 2012 at 3:09pm
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..

Jun 16, 2012 at 3:18pm
Make sure ~VisualShape() is virtual.
Jun 16, 2012 at 3:23pm
It is virtual (in base graphic class)..

virtual ~VisualShape()
{
}

Do I need to put some code here ?
Jun 16, 2012 at 3:29pm
¿Do you need to release resources?

You shouldn't call the destructor directly, just use delete
Jun 16, 2012 at 3:36pm
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();
}
Jun 18, 2012 at 8:04am
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();
}
Jun 18, 2012 at 9:29am
When unsure, add printing. Answer is: looks fine to me.
http://ideone.com/lDU8B
Jun 18, 2012 at 11:00am
Maybe class VisualShape has data that it doesn't free?
Topic archived. No new replies allowed.