Database.Purge() is a bit of a misnomer, in my opinion. That function doesn't purge items, it just tells you whether or not they are safe to erase -- you do have to erase them yourself. You can erase them without using Database.Purge(), but you can easily corrupt your drawing that way.
Something like the following should do the trick. Note that it doesn't guarantee that linetypes other than continuous are unreferenced; your drawings could have entities that reference those linetypes directly. You may want to script a call to the 'setbylayer' command prior to running your purge command, or scan all the BlockTableRecords yourself, or rename any linetypes that remain after calling your purge command, or otherwise deal with that possibility.
[CommandMethod("purgelts")]
public void purgelinetypes()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
ObjectIdCollection ltypeIds = new ObjectIdCollection();
using (Transaction t = db.TransactionManager.StartTransaction())
{
LinetypeTable ltt = t.GetObject(db.LinetypeTableId, OpenMode.ForRead)
as LinetypeTable;
foreach (ObjectId ltypeId in ltt)
{
if (ltypeId == SymbolUtilityServices.GetLinetypeByBlockId(db)) continue;
if (ltypeId == SymbolUtilityServices.GetLinetypeByLayerId(db)) continue;
if (ltypeId == SymbolUtilityServices.GetLinetypeContinuousId(db)) continue;
ltypeIds.Add(ltypeId);
}
LayerTable lt = t.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
foreach (ObjectId ltrId in lt)
{
if (ltrId.IsErased) continue;
LayerTableRecord ltr = t.GetObject(ltrId, OpenMode.ForWrite) as LayerTableRecord;
ltr.LinetypeObjectId = db.ContinuousLinetype;
}
t.Commit();
}
ed.WriteMessage("Checking whether {0} linetypes can be purged.\n", ltypeIds.Count);
db.Purge(ltypeIds);
ed.WriteMessage("{0} linetypes can be purged.\n", ltypeIds.Count);
using (Transaction t = db.TransactionManager.StartTransaction())
{
foreach (ObjectId ltypeId in ltypeIds)
{
DBObject ltype = t.GetObject(ltypeId, OpenMode.ForWrite);
ltype.Erase();
}
t.Commit();
}
db.ReclaimMemoryFromErasedObjects(ltypeIds);
}