- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, guys!
I saw two articles about dispose objects here, and here. And then, i understand by resuming that i just have to manual dispose (by using or .dispose) newly objects derived from DBObject.
Based on that, my first doubt is: Could I not dispose the Result Buffer in the code below?
public static void SetXRecord(DBObject dbObj, string key, string value)
{
Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
DBObject obj = tr.GetObject(dbObj.ObjectId, OpenMode.ForWrite);
if (obj == null) return;
if (obj.ExtensionDictionary.IsNull) obj.CreateExtensionDictionary();
DBDictionary dic = tr.GetObject(obj.ExtensionDictionary, OpenMode.ForWrite) as DBDictionary;
Xrecord xrec;
if (dic.Contains(key))
{
xrec = tr.GetObject(dic.GetAt(key), OpenMode.ForWrite) as Xrecord;
}
else
{
xrec = new Xrecord();
//if (!dic.IsWriteEnabled) tr.GetObject(dic.ObjectId, OpenMode.ForWrite);
dic.SetAt(key, xrec);
tr.AddNewlyCreatedDBObject(xrec, true);
}
// ######## ~ HERE I DISPOSE BUT I CANT HAVE TO ~ ##########
using (ResultBuffer rb = new ResultBuffer(new TypedValue((int)DxfCode.Text, value)))
{
xrec.Data = rb;
}
tr.Commit();
}
}
I know is there a post quite similar here, but cleaely the theme divide opinions, and i can't conclude what is the best pratice.
So, two doubts about that subject for this post:
1. In that sample, do i have to Dispose Result Buffer? (code works perfect do it or not)
2. In general, can i trust in GC and just use Dispose in cases indicatade in the posts that i put above? Or is a best pratice do to always i can, in all objects that implement IDisposable?
Thanks in advance.
Solved! Go to Solution.