C Language and Libraries Help (clang.hlp) (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
delete
                                             Up Contents Index Back
─────C/C++ Language─────────────────────────────────────────────────────────
 
  Keyword:  delete
 
  Syntax:   [::] delete pointer
            [::] delete [] pointer
 
  Summary:  Deallocates a block of memory. The argument <pointer>
            must point to a block of memory previously allocated by the
            new operator. If <pointer> points to an array, place empty
            brackets before <pointer>.
 
  See also: new, __near, __far, __huge, __based
            Memory Models
            Customizing the Delete Operator
 
     The run-time library provides four versions of the delete
     operator to deallocate pointers that are near, far, huge, or
     based. The version that is selected depends on the addressing mode
     of <pointer> (for example, if it's a near pointer, the near delete
     operator is called).
 
     If the addressing mode of <pointer> doesn't reflect the version of
     the new operator that was used to allocate the memory, the
     incorrect version of the delete operator is called. For example:
 
         Node __far *fpN;
         fpN = new Node __near;  // convert near to far
         delete fpn;             // far delete invoked for near object
 
     Here, the compiler chooses the inappropriate delete operator
     for the pointer, which results in a run-time error. To prevent
     this problem, explicitly cast the pointer to the desired
     addressing mode:
 
         delete (Node __near *)fpN;
                                    -♦-