< previous page page_982 next page >

Page 982
0982-01.gif
Figure 17-6
Allocating Dynamic Data on the Free Store
Using the previous example, we can deallocate the dynamic data pointed to by intPtr and nameStr with the following statements.
delete intPtr;
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Retruns the variable pointed to by intPtr to the free store to be used again. The value of intPtr is then undefined.
delete [] nameStr;
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Returns the array pointed to by nameStr to the free store to be used again. The value of nameStr is then undefined.*

After execution of these statements, the values of intPtr and nameStr are undefined; they may or may not still point to the deallocated data. Before using these pointers again, you must assign new values to them (that is, store new memory addresses into them).
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif 3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
*The syntax for deallocating an array, delete [ ] nameStr, may not be accepted by some compilers. Early versions of the C++ language required the array size to be included within the brackets: delete [6] nameStr. If your compiler complains about the empty brackets, include the array size.

 
< previous page page_982 next page >