Hi,
i need to read an external dwg and import only some entities.
I use WblockCloneObjects, it work fine but i found a memory problem, the memory is not disposed
and autocad memory process significantly increases after WblockCloneObjects.
I tried both autocad 2013 and 2014, but same result, autocad memory increase and not disposed.
Where is the problem?
Thank you very much.
Code:
[CommandMethod("TestClone", CommandFlags.Transparent)]
public void TestClone()
{
// repeated 20 times to highlight the memory consumption
for (int i = 0; i < 20; i++)
{
ObjectIdCollection filteredIds = new ObjectIdCollection();
Database targetDb = ACAP.Application.DocumentManager.MdiActiveDocument.Database;
using (Transaction trMain = targetDb.TransactionManager.StartTransaction())
{
using (Database db = new Database(false, true))
{
// read the source dwg
db.ReadDwgFile(@"D:\he10t.dwg", FileOpenMode.OpenForReadAndAllShare, true, "");
// get all entities
using (Transaction trSource = db.TransactionManager.StartTransaction())
{
BlockTable pBT = (BlockTable)trSource.GetObject(db.BlockTableId, OpenMode.ForRead, false);
BlockTableRecord pBTR = (BlockTableRecord)trSource.GetObject(pBT[BlockTableRecord.ModelSpace], OpenMode.ForRead, false);
foreach (ObjectId id in pBTR)
{
// ...open entity and filter
filteredIds.Add(id);
}
}
// clone the filtered entities in current document
using (ACAP.DocumentLock dl = ACAP.Application.DocumentManager.MdiActiveDocument.LockDocument())
{
using (IdMapping mapping = new IdMapping())
{
// now clone the objects into the destdb
ObjectId destDbMsId = SymbolUtilityServices.GetBlockModelSpaceId(targetDb);
db.WblockCloneObjects(filteredIds, destDbMsId, mapping, DuplicateRecordCloning.Replace, false);
}
}
}
trMain.Commit();
}
filteredIds.Dispose();
}
}