Author Topic: ObjectIdCollection : DisposableWrapper  (Read 1722 times)

0 Members and 1 Guest are viewing this topic.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
ObjectIdCollection : DisposableWrapper
« on: November 12, 2014, 08:14:35 AM »
Code - C#: [Select]
  1. [Wrapper("AcDbObjectIdArray")]
  2. public sealed class ObjectIdCollection : DisposableWrapper, IList;
Must I to call the Dispose() method for the ObjectIdCollection instance which was created by me?

Thank you.

Gasty

  • Newt
  • Posts: 90
Re: ObjectIdCollection : DisposableWrapper
« Reply #1 on: November 14, 2014, 12:42:24 AM »
Hi,

I think there is no need to dispose if you use the resource inside a "using" statement, otherwise the gc will hit it eventually. So if you are dealing with a *very* large collection you should either use inside a "using" or dispose it at the end of its life cycle.

Gaston Nunez

owenwengerd

  • Bull Frog
  • Posts: 451
Re: ObjectIdCollection : DisposableWrapper
« Reply #2 on: November 14, 2014, 11:38:45 AM »
If objects are disposable, you should call Dispose(). If you don't call it explicitly, Dispose() will be called by the garbage collector outside of your control. In many cases, the objects are disposable precisely because they are not thread-safe, and could therefore crash or corrupt the process when disposed from the GC thread. As Gaston mentioned, it's generally best to call Dispose() indirectly via the using statement.