Nested document objects

Nested document objects

pjones3
Contributor Contributor
769 Views
6 Replies
Message 1 of 7

Nested document objects

pjones3
Contributor
Contributor
Why would nesting
{code}
Document doc = Application.DocumentManager.MdiActiveDocument;
{code}
affect each other? I have a plotting routine that creates its own document object. In that routine I call another routine that inserts a block. In that second routine I create another document object as above. Also in that routine, I use the using (doc) command. However, when it leaves that routine, the first doc becomes null and it throws an exception. Shouldn't those two separately created doc objects be, well, separate entities?

Would it be better to pass the document object from the first routine to the routine(s) it calls?

This all started because I was trying to remove all my objects and not wait for the garbage collection.

Patrick
0 Likes
770 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
You should never call Dispose() on a Document object.

If you're using the using() construct on a Document, that's
the problem.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message
news:[email protected]...
Why would nesting
{code}
Document doc = Application.DocumentManager.MdiActiveDocument;
{code}
affect each other? I have a plotting routine that creates its own document
object. In that routine I call another routine that inserts a block. In that
second routine I create another document object as above. Also in that routine,
I use the using (doc) command. However, when it leaves that routine, the first
doc becomes null and it throws an exception. Shouldn't those two separately
created doc objects be, well, separate entities?

Would it be better to pass the document object from the first routine to the
routine(s) it calls?

This all started because I was trying to remove all my objects and not wait for
the garbage collection.

Patrick
0 Likes
Message 3 of 7

pjones3
Contributor
Contributor
Thank you for the response. I had to think about this for a while. I could not understand why I should not Dispose() or use using() on a document object. I was focusing on it just being an object. Then it hit me 🙂

Patrick
0 Likes
Message 4 of 7

Anonymous
Not applicable
Well, technically speaking, you should be able to call
Dispose() on any object, without any kind of adverse
consequences, but Autodesk doesn't seem to agree,
and considering the massive confusion surrounding
IDisposable more generally, I would have to disagree
with their view.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message
news:[email protected]...
Thank you for the response. I had to think about this for a while. I could not
understand why I should not Dispose() or use using() on a document object. I
was focusing on it just being an object. Then it hit me 🙂

Patrick
0 Likes
Message 5 of 7

pjones3
Contributor
Contributor
Agreed. Logically, Dispose() should just work on the object as it pertains to memory where Close(), etc. should work on the thing the object references.
0 Likes
Message 6 of 7

Anonymous
Not applicable
Dispose() has nothing to do with memory allocation
or deallocation.

Dispose() is nothing but a standardized way that you can
use to inform an object that you're done using it, and will
not use it any further.

What exactly that means to each object that implements
IDisposable is entirely up to the object. In some cases,
it does nothing, in other cases, it releases resources or
closes things, but in fact, it never causes an object to be
deleted or destroyed. Reclaiming the memory used by
an object is always done by the framework, once it has
determined the object is unreachable.


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message
news:[email protected]...
Agreed. Logically, Dispose() should just work on the object as it pertains to
memory where Close(), etc. should work on the thing the object references.
0 Likes
Message 7 of 7

pjones3
Contributor
Contributor
I meant basically the same thing I just didn't put is so eloquently 🙂
Where I stated memory, I should have put resources. I have always considered them
to be the same. Old habit.
0 Likes