02-13-2007 04:21 PM
02-14-2007 09:38 AM
02-14-2007 01:34 PM
Hi Bilal,
first of all thanks for taking a look at my post.
Let me rephrase my problem from a C++ point of view.
In the past (long before something similar showed up in COM) I implemented smart pointers/handlers (implemented as objects) with automatic ref count increments and decrements by overloading copy constructor, assignment operator, etc. From that moment on I didn't have to worry about freeing memory too soon or too late. In the case of a (C) VISA session encapsulated in a C++ object (smart pointer/handle), I didn't have to worry how many times it was referenced. As soon as it was no longer referenced, the destructor was invoked and the (C) VISA session was closed, ready for immediate use by someone else.
Unfortunately Microsoft decided not to use ref counting (e.g. to avoid issues in the case of circular references, which fortunately I didn't have to deal with) ... so I tried to find a clean method which would do something similar in C# as I was able to do using C++ (after adding smart pointers/handles). The only way (to my humble knowledge ) is to use the Dispose() method in order not to wait for the GC to kick in at an undetermined moment in the near or far future ... however at that moment (again to my humble opinion) there is no way to know that the Session is no longer referenced (either directly or indirectly). Verifying IsDisposed() - each time I want to use the Session - is not really a solution ...
Perhaps there are clever guys out there who can convince me that indeed there is a clean solution to my problem in .NET ...
Thanks again,
Frans.
02-16-2007 08:24 AM