문제

How is unmanaged memory allocated in system when COM objects or any other unmanaged instances are created from C#?

도움이 되었습니까?

해결책

The CLR creates a Runtime Callable Wrapper (RCW) for the COM objects you want to instantiate. This is a kind of interop proxy from .NET to the COM system. The COM object you create is therefore allocated and a reference to it created in the CLR, which puts it on the heap.

You must always implement IDisposable in the class that holds references to RCWs, because they are not automatically cleaned up (the wrappers are on the .NET heap, but the COM objects themselves are not). Calling Dispose() on the wrapper releases the COM objects. Not implementing IDisposable therefore causes memory leaks.

다른 팁

My guess is they result in a call to the OS to create their memory on the unmanaged heap. The CLR would obviously have nothing to do with them as they are unmanaged.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top