C ++ / CLI helps create forests IDisposablefor you when you implement the ref class destructor. Also, if you do not implement a destructor, but your class has a member variable that implements IDisposable, then IDisposableit is automatically implemented in your class again. This is very useful and much better than being IDisposablehandled in C #.
I came across this behavior when implementing a ref class that holds onto msclr::com::ptr(a smart pointer containing RCW).
ref class Test
{
msclr::com::ptr<IWhatever> _aComObject;
}
In my specific case, the COM object referenced by my class does not “block” some unmanaged resource; it actually just uses some unmanaged memory that the CLR cannot see. Therefore, I would like not to confuse the users of my ref class without having to execute the IDisposableclass. Instead, I want the CLR to know about the existence of a COM object using the GC API to add the appropriate memory pressure.
So the question is: is there a way to suppress the implementation IDisposableof the ref class, which does not implement the destructor, but retains the member variable IDisposable?
NB: , COM-, IDisposable ref, Dispose ref.
, msclr:: com:: ptr .
IDisposable. .
_aComObject msclr:: com:: ptr (msclr::com::ptr<IWhatever>^). Test "" com ptr , Test .