(1) Use new to obtain and specify a common format for allocating memory for a data object:
TypeName * Pointer_name=new typeName;
(2) Use Delete to free up memory
Delete Pointer_name;
It is important to note that delete frees the memory of the data object that the Pointer_name line is in. The Delete also applies to releasing the memory requested with new.
The C + + standard states that you do not attempt to free memory that has been freed, and you cannot use Delete to free the memory that is obtained by declaring the variable.
int age=23;
int * page=&age;
Delete page; This is an illegal operation.
Note: the key to using delete is to use it for the memory allocated by new. This does not mean that you want to use the pointer for new, but rather the address of new.
int * Ps=new int;
int * PQ=PS;
Delete PQ;
In general, do not create two pointers to the same block of memory, as this will increase the likelihood of the error of deleting the same memory block two times.
006--c++ Dynamic Memory (Introduction)