remove() Functions
To search for and remove particular items, you can use the functions remove() and removeAndDestroy():
 
virtual RWCollectable* remove(const RWCollectable*);
virtual void removeAndDestroy(const RWCollectable*);
The function remove() looks for an item that is equal to its argument and removes it from the collection, returning a pointer to it. It returns nil if no item is found.
The function removeAndDestroy() is similar except it deletes the item instead of returning it, using the virtual destructor inherited by all RWCollectable items. You must be careful when using this function that the item was actually allocated off the heap, not the stack, and that it is not shared with another collection.
The following example, which expands on the previous one, demonstrates the use of the virtual function removeAndDestroy():
 
RWCollectable* oust = sc.remove(&dummy); //11
delete oust; //12
sc.removeAndDestroy(&dummy); //13
//11 Removes the first occurrence of the string containing Mary and returns a pointer to it. This pointer will be nil if there is no such item.
//12 Deletes the item, which was originally allocated off the heap. There is no need to check the pointer against nil because the language guarantees that it is always OK to delete a nil pointer.
//13 In this statement, the remaining occurrence of Mary is both removed and deleted.