When to use Dispose?
|Top Previous Next|
You should use Dispose with Timer objects for example, but also with Database and TransactionManager objects.
But if you use the using statement as show below you do not have to Dispose of them because it is done automatically:
using (var tr = db.TransactionManager.StartOpenCloseTransaction())
using (var sideDb = new Database(false, true))
sideDb.ReadDwgFile(sSourceFullFileName, FileOpenMode.OpenForReadAndAllShare, true, null);
...bool bChanged = AcadHelpers.FindAndReplaceTextEntities(sideDb, sOldStrings, sNewString);
Which presumanbly means a Database not created within using needs to be explicitly disposed.