Jump to content

WblockClon​eObjects memory not disposed


Recommended Posts


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 autocad memory process significantly increases after every WblockCloneObjects.


Where is the problem?


Thank you very much.

[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[blockTabl​eRecord.ModelSpace], OpenMode.ForRead, false);

                           foreach (ObjectId id in pBTR)
                               // ...open entity and filter

                       // 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(targetD​b);

                               db.WblockCloneObjects(filteredIds, destDbMsId, mapping, DuplicateRecordCloning.Replace, false);

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...