TheSwamp
Code Red => .NET => Topic started by: dketels on February 24, 2023, 10:05:47 AM
-
Hi,
i have a question regarding Disposing an object.
I implemented a handler for the "AddHandler document.Database.ObjectAppended" event.
The signature of the method is "Private Sub HandleAppendedEvent(sender As Object, e As ObjectEventArgs)"
Just like a .net Polyline is a wrapper object and should be disposed, I should also dispose the e.DBObject?
What is your opinion?
-
This may help resolve your query.
https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-FE7D58D5-28A0-4C98-A876-D4D48F06D0B2
I don't understand the
e.DBObject , what is this ?
Perhaps you could post your implementation.
Regards,
-
Hi,
You do not need to dispose the e.DBObject. This DBObject is already handled by the command (or whatever) which appended it to the Database.
-
Hi, thank you for the response.
After reading your replies and doing some more research I removed the dispose of the object given in the event argument.
My reasoning is that, because I (any of my commands) did not create the object, I should not dispose of it.
Details:
In this case, it was an Xrecord that was appended to the database by autocad. In the HandleAppendEvent, I look at the object, and if it is for example a polyline I would do stuff with it.
I used to believe that, because I accessed the object, just to be sure, I needed to dispose it.
But in case of the Xrecord, me disposing it, made it unavailable to autocad, which was still busy with it. Resulting in a read/write exception and autocad crashing.