c++ cli - Should a managed class that wraps a DirectSound interface be IDisposable? -


I'm writing a managed cover around DirectSound. (This is a simple partial cover that resolves my specific problem and nothing else. Do not tell me or tell me anything.) Does a managed client hide the IDirectSound8 and why? Same question about IDirectSoundBuffer8

Technical: Yes. Practically: No. IDirectSound8 is a COM interface, they are very easily wrapped in .NET with an interop library. An RCW calculates the reference on the built-in COM concluse object in RCW, an RCD implementing the not idisposition, even if it is hanging on very unmanaged resources.

The reason for this is not because it is almost impossible to implement IDisposable correctly. A COM cockless applies several interfaces, so any reference is added to the count. You must be 100% sure that the all of those interface points will no longer be used before a settlement is secure. It is very difficult to do, those indicators are created in an unexpected way. Like the indexed property of one of the interfaces, the intermediate interface pointer never appears in your code.

This is not a real problem, the garbage collector takes care of the reference numbers, it gets done finally. This is just because the object takes a little longer to be released. Standard GC behavior Unfortunately the out-of-process com server has side-effects, the programmers get annoyed when the process does not disappear from the immediate task manager list, then their code stops using the interface. There are many "excel / word left" at the forums here.

If you want to implement it anyway, you can do this by calling Marshal. Finelrech Com Object () implementation in your Dispos () Be careful of the increased danger for failure, it is very difficult to find the wrong call to detect failure. The original code is not exactly the opposite of removing an object and it still has an indicator. If it is actually a "heavy" item that is released immediately, then GC The compiler () + GC WaitForPendingFinalizers () is also done with very little risk of getting this work done wrong. With the side effects of the course.


Comments