Functions clear() and clearanddestroy() – HP Integrity NonStop J-Series User Manual
Page 162

a window on which the object is to be drawn.
Note that the apply() functions of the Smalltalk-like collections and the generic collections are
similar. (Compare
.) The difference is in the type of the first argument
of the user-supplied function: the Smalltalk-like collections use RWCollectable*, while the
generic collections use type*. With both sets of collections, you must be careful that you cast the
pointer item to the proper derived class.
The apply functions generally employ the most efficient method for examining all members of the
collection. This is their great advantage. Their disadvantage is that they are slightly clumsy to use,
requiring you to supply a separate function
[18]
.
Functions clear() and clearAndDestroy()
To remove all items from the collection, you can use the functions clear() and clearAndDestroy():
virtual voidclear();
virtual voidclearAndDestroy();
The function clearAndDestroy() not only removes the items, but also calls the virtual destructor
for each item. You must use this function with care. The function does check to see if the same
item occurs more than once in a collection (by building an
RWIdentitySet
internally), and thereby
deletes each item only once. However, it cannot check whether an item is shared between two
different collections. In particular, you should never call clearAndDestroy() on a collection which
holds an instance of RWnilCollectable, which will almost be shared. You must also be certain that
every member of the collection was allocated off the heap.