By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,853 Members | 1,052 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,853 IT Pros & Developers. It's quick & easy.

IDisposable

P: n/a
My main project is an MFC application. Its document class derives from
COleServerDoc and I have implemented an Automation interface based on
IDispatch. I am using VisualBasic to test the Automation interface. After
moving to VB.NET, I have gotten into trouble when releasing my document
objects.

Earlier, I used the syntax

MyDoc = Nothing

to tell that the document had been closed in the server application and that
the object was no longer valid. With VB.NET, this doesn't seem to work in
the same way. It appears that the object is still 'in use' somehow after
this statement, and I get different kind of errors in VB if my server cleans
up ('delete this') the document object. If I leave the MFC document object,
everything seems to work fine, except that the document object is left in
memory - and thus the server application will also be left in memory after
exiting the VB client.

I have now read just a little bit about the garbage collection mechanism in
VB.NET, and suspects that this has something to do with the problem. The VB
object is not actually released when you say "= Nothing", right ?.

My question is: Will it help implementing an IDisposable interface on my
document object (in MFC) ? Will VB.NET be able to see it and use it ? Could
I then call .Dispose() directly to make sure the document object is released
? Or is there some other way in VB to explicitly dispose the object ?

Appreciate any help or clues whatsoever!

Bendik
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Bendik,

The first simple solution can be to open a compenent item and create your
code in that.
With using that is Idisponsable direct implemented.

Just a thought,

Cor
ps. when you have an answer in a newsgroup where you have multiposted this
question, can you than everywhere else add the right answer to all those
posts. Maybe it is in future better to crosspost, than you can do that in
one time.

Nov 21 '05 #2

P: n/a
I have now realized that the idea of implementing IDisposable in my COM
server was a wrong path. If I understand it correctly, IDisposable is an
interface intended for components using managed code, and my server is MFC
(unmanaged). So I guess VB.NET would never 'see' my possible IDisposable
implementation...

I think I am quite close to understanding the problem now, but I am nowhere
near a solution: Everything works fine now if I set

MyDoc = Nothing

in the VB client and just leave the document open in the server. When the
server is closed down eventually, it will release everything and shut down
normally. However, if I call my server's 'CloseDocument' method from the
client before setting it to Nothing, something is not released, and it will
be stuck when shutting down. I have tried to monitor reference counts in my
MFC server through debugging, but it seems to be so many references that it
is difficult keep track of them (ref cnt is sometimes going up to 11, and
never down to 0 !??).

I am really running out of ideas how to solve this. Any other clues from
someone would be greatly appreciated!

Bendik
Nov 21 '05 #3

P: n/a
Bendik,

I saw your answer in the general group before this so my answer about
multiposting stays.

However I do not know how it affects to your code but Idisposable "should"
take care of the release of unmanaged resources.

http://msdn.microsoft.com/library/de...classtopic.asp

I hope this helps somehow to find your solution.

Cor

"Bendik Engebretsen" <ki****************@tfoshcet.on>
I have now realized that the idea of implementing IDisposable in my COM
server was a wrong path. If I understand it correctly, IDisposable is an
interface intended for components using managed code, and my server is MFC
(unmanaged). So I guess VB.NET would never 'see' my possible IDisposable
implementation...

I think I am quite close to understanding the problem now, but I am
nowhere near a solution: Everything works fine now if I set

MyDoc = Nothing

in the VB client and just leave the document open in the server. When the
server is closed down eventually, it will release everything and shut down
normally. However, if I call my server's 'CloseDocument' method from the
client before setting it to Nothing, something is not released, and it
will be stuck when shutting down. I have tried to monitor reference counts
in my MFC server through debugging, but it seems to be so many references
that it is difficult keep track of them (ref cnt is sometimes going up to
11, and never down to 0 !??).

I am really running out of ideas how to solve this. Any other clues from
someone would be greatly appreciated!

Bendik

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.