Author Topic: Kean Walmsley on Dispose()  (Read 8440 times)

0 Members and 1 Guest are viewing this topic.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Kean Walmsley on Dispose()
« Reply #15 on: August 24, 2012, 12:47:22 AM »
How about when a transaction is responible for its lifetime as in object created with GetObject()? But not sure how transaction stores them ,
 
Also it would be nice if they explained if Close() and Dispose() were semantically equivalent and if not how they differ might help avoid a lot of confusion.
 
Code - C#: [Select]
  1.  
  2.  internal unsafe static DBObject GetObjectInternal(AcDbTransactionManager* pTM, ObjectId id, OpenMode mode, [MarshalAs(UnmanagedType.U1)] bool openErased, [MarshalAs(UnmanagedType.U1)] bool forceOpenOnLockedLayer)
  3. {
  4.     AcDbObject* value;
  5.     int objectInTransaction = (int)<Module>.GetObjectInTransaction(ref value, pTM, *(AcDbObjectId*)(&id), (AcDb.OpenMode)mode, openErased, forceOpenOnLockedLayer);
  6.     if (objectInTransaction != 0)
  7.     {
  8.         throw new Exception((ErrorStatus)objectInTransaction);
  9.     }
  10.     IntPtr unmanagedPointer = new IntPtr((void*)value);
  11.     return (DBObject)RXObject.Create(unmanagedPointer, false);
  12. }
  13.  
« Last Edit: August 24, 2012, 12:55:01 AM by Jeff H »

TheMaster

  • Guest
Re: Kean Walmsley on Dispose()
« Reply #16 on: August 24, 2012, 03:30:40 AM »

Tony, et al

Regarding autoDelete :
Under what circumstances would the autoDelete property be false ?

The constructors for (say) a line sets the property to true through the base class.

Just an aside.
It pleases me immensely to see the level of discussion on these subjects.
Thanks to all who are participating and attempting to clear up concepts that have been in dispute for years.

Regards,
Kerry

It depends on the managed wrapper type.  For DBObject, AutoDelete will be false if there is no need to delete the underlying AcDbObject or call close() if the object is in a database.

In the case of the constructor, AutoDelete will always be true, because the underlying AcDbObject is owned by the managed wrapper and must be deleted or added to a database.

When you add a new DBObject to a database, and then call AddNewlyCreatedDbObject() to add it to a transaction, the transaction sets the DBObject's AutoDelete property to false:

Code - C#: [Select]
  1.  
  2. public virtual unsafe void AddNewlyCreatedDBObject(DBObject obj, bool add)
  3. {
  4.    AcDbTransactionManager* impObj = this.GetImpObj();
  5.    int num2 = *(((int*) impObj)) + 48;
  6.    int num = *num2[0](impObj, obj.GetImpObj(), add);
  7.    if (num != 0)
  8.    {
  9.       throw new Exception((ErrorStatus) num);
  10.    }
  11.    obj.AutoDelete = false;  <--- no longer necessary to delete the AcDbObject
  12. }
  13.  

When you call Transaction.GetObject() to open an object, the resulting DBObjectt's AutoDelete property is always false. If you call ObjectId.Open() to open an object, its AutoDelete property is always true (because Close() or Cancel() must be called).

For other objects, it depends on whether the underlying unmanaged object should be deleted.