473,396 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

IDisposable

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
3 2599
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Samuel R. Neff | last post by:
I'd like some opinions on whether or not to use IDisposable for classes that require clean-up but when the clean-up is not related to unmanaged resources or other disposable objects. The most...
5
by: Robert Heuvel | last post by:
Hi, this is what I did: public struct SWaitCursor:IDisposable { public SWaitCursor (int i) { Cursor.Current = Cursors.WaitCursor; } void System.IDisposable.Dispose() { Cursor.Current =...
3
by: Dave | last post by:
I trying to determine the best pattern for designing my business and data layers... Can the instance of the business object eventually cause memory leaks in Example 1? If your business class...
4
by: Helge Jensen | last post by:
In C# 2.0 System.IO.Stream is declared as: public class Stream: ..., IDisposable { ... public void Dispose(); public void Dispose(bool); IDisposable.Dispose(); } Which must be a...
4
by: phl | last post by:
hi, My question is: 1. To avoid possible memory leaks, when you use this pattern, after you have dealth with the unmanaged resources and before you take your object off the finalize queue,...
6
by: Water Cooler v2 | last post by:
I heard from someone that we must not implement IDisposable for all classes. Can someone please tell me: 1. the reason why we must not implement IDisposable for all the classes we write. 2....
12
by: Cordell Lawrence \(News Group\) | last post by:
There an ongoing discussion between a colleague and myself about the usefulness of the IDisposable pattern beyond the reclamation of unmanaged resources. The discussion is somewhat lengthy so I...
12
by: Mark Rae | last post by:
Hi, The following code works: HttpWebRequest objRequest = null; try { HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create("http://www.microsoft.com"); using (HttpWebResponse...
11
by: Mark Rae | last post by:
Hi, Following on from the recent thread about why HttpWebRequest doesn't implement the IDisposable interface, I got to wondering whether people make their custom classes inherit IDisposable or...
3
by: Mark | last post by:
If your class implements IDisposable, I was told that this increases the speed with which your class is garbage collected. Is this true? And if so, how much "time" does it save? Assume that we...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.