Author Topic: To Dispose or not to dispose, that's an old question?  (Read 1536 times)

0 Members and 1 Guest are viewing this topic.

dketels

  • Mosquito
  • Posts: 2
To Dispose or not to dispose, that's an old question?
« 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?

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2071
  • class keyThumper<T>:ILazy<T>
Re: To Dispose or not to dispose, that's an old question?
« Reply #1 on: February 24, 2023, 03:25:45 PM »

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,
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00


some people complain about loading the dishwasher

Sometimes the question is more important than the answer.

gile

  • Water Moccasin
  • Posts: 2493
  • Marseille, France
Re: To Dispose or not to dispose, that's an old question?
« Reply #2 on: February 24, 2023, 04:44:39 PM »
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.
« Last Edit: February 24, 2023, 04:51:59 PM by gile »
Speaking English as a French Frog

dketels

  • Mosquito
  • Posts: 2
Re: To Dispose or not to dispose, that's an old question?
« Reply #3 on: February 28, 2023, 02:38:42 AM »
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.