The greatest enemy of mankind is forgetting. --- Lazy voice
This problem is easy to find, because it is a typical issue.
For example:
I,
Object is a class,
Object * object = new object [3];
... Balabala...
Delete object; // Problem
At this time, memory leakage is triggered, because only the memory of the object [0] is released (the compiler calls the Destructor once with the address of & object [0 ),
Equivalent to delete [1] object;
The correct release should be Delete [] object;
Or delete [3] object;
2. Complicated
Object is a class,
Object ** object = new object * [3]; // only a pointer array of three object objects is dynamically allocated, but they are not objects themselves.
// Allocate
For (INT I = 0; I <3; ++ I)
{
Object [I] = new object ();
}
... Balabala...
Delete [] object; // Problem
In fact, this also causes memory leakage. In this case, delete is only a pointer rather than an object to which it points.
To do this, you can:
For (INT I = 0; I <3; ++ I)
{
Delete object [I];
}
Delete object;