This is a snippet of my code used to remove an Xrecord
I loop also an add Xrecord (same dictionary ecc..) and i've tried to force a GC.Collect after this but the system memory increased
Why the memory increased ? after the first Add i supposed it's remain constants (first delete --> after add )
// The Main loop is
for (int k = 0; k < 100000; k++)
{
SetDATAXRecord(mydocument, mydataset);
}
void SetDATAXRecord(Document d, Dataset ds)
{
// the first time this skip and return..
b2XRec.deleteEntryXRecordFromDictionary("mydictname", "mylabel");
// add xrecord...
b2XRec.setDatasetInXrecord(ds, "mydictname", "mylabel");
GC.Collect();
}
public static bool deleteEntryXRecordFromDictionary(string dictionaryName, string nameEntry)
{
ObjectId idremoved = ObjectId.Null;
DBDictionary mioDizionario = null;
using (DocumentLock docLock = m_document.LockDocument())
{
SetDbFromDocument();
using (Transaction trans = db.TransactionManager.StartTransaction())
{
try
{
// First, get the NOD...
using (DBDictionary dict = (DBDictionary)trans.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForWrite))
{
if (dict.Contains(dictionaryName))
{
ObjectId idXrecDict = dict.GetAt(dictionaryName);
mioDizionario = (DBDictionary)trans.GetObject(idXrecDict, OpenMode.ForWrite);
if (mioDizionario.Contains(nameEntry))
{
idremoved = mioDizionario.Remove(nameEntry);
using (Xrecord pEnt = (Xrecord)trans.GetObject(idremoved, OpenMode.ForWrite, false, true))
{
pEnt.Erase();
}
}
mioDizionario.Erase();
// mioDizionario.ReleaseExtensionDictionary();
trans.Commit();
}
}
}
catch (Autodesk.AutoCAD.Runtime.Exception e)
{
MessageBox.Show(e.Message);
trans.Abort();
return false;
}
}
}
return (idremoved != ObjectId.Null);
}
[edit: codetags added]