The purge mechanism allows you to erase unused objects in the database. If an object has a hard owner or pointer reference, it cannot be purged. The purge() function of AcDbDatabase is invoked on the set of objects specified in the ID array:
AcDbDatabase::purge(AcDbObjectIdArray &idArray);
The purge() function returns in the same ID array the IDs of the objects that can be purged (that is, that have no hard references to them). Once you have this array of object IDs, you are responsible for erasing the objects.
When a drawing is loaded, AutoCAD goes through the database and purges unreferenced anonymous blocks and nested xref blocks. These blocks are erased when the drawing file is closed. If you create any anonymous blocks between the open and close of a drawing, they will be purged without your knowledge unless you protect them by calling the standalone function acdbSetReferenced(). This purging occurs even if the objects have hard references to them.