Results 1 to 3 of 3

Thread: WblockClon​eObjects memory not disposed

  1. #1
    Woo! Hoo! my 1st post
    Join Date
    2015-01
    Posts
    1
    Login to Give a bone
    0

    Default WblockClon​eObjects memory not disposed

    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[BlockTabl​eRecord.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(targetD​b);
    
                                    db.WblockCloneObjects(filteredIds, destDbMsId, mapping, DuplicateRecordCloning.Replace, false);
                                }
                            }
                        }
                        trMain.Commit();
                    }    
                    filteredIds.Dispose();
                }
                
            }

  2. #2
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,396
    Login to Give a bone
    0

    Default Re: WblockClon​eObjects memory not disposed

    How are you determining that memory is increasing? Are you getting any errors?
    C:> ED WORKING....

  3. #3
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: WblockClon​eObjects memory not disposed

    Your ObjectIdCollection filterIds is only in scope for the CommandMethod, so there's no need to call Dispose();

    As for the DBObjects accessed via GetObject(), by wrapping your Transaction in a using statement (as I understand it), it (the Transaction) is aware of the Objects accessed, and disposes of them for you once you Commit() the Transaction, and exit the using statement.

    With regard to the side Database, Owen's pretty well covered that with you already in your duplicate thread, no?

    Otherwise, you might experiment to see if there's any difference in using StartOpenCloseTransaction() in lieu of StartTransaction().



    Separately, this article from Kean might be of use:

    Cleaning up after yourself: how and when to dispose of AutoCAD objects in .NET



    Cheers
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

Similar Threads

  1. 2011: Memory Crash (running out of memory)
    By gfreddog in forum AutoCAD General
    Replies: 9
    Last Post: 2012-04-19, 08:16 PM
  2. Out of Memory
    By kmarquis in forum Revit Architecture - General
    Replies: 27
    Last Post: 2012-01-30, 04:33 AM
  3. Replies: 4
    Last Post: 2011-09-13, 12:17 PM
  4. Question about memory and peak memory
    By gbelous in forum Hardware
    Replies: 1
    Last Post: 2010-04-02, 01:48 PM
  5. Replies: 3
    Last Post: 2009-10-03, 04:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •