Re: Simple problem: Why does this cause a massive memory leak?
Ok maybe I was not clear on what I said. The IDisposablie if for a .NET
Object not for COM. If the COM has a problem very true you fix it there..,
but any time you use Unmanaged code and reference in a .NET app, please wrap
it in a object with IDisposiable implementation and make sure you call
..Dispose() after done with the .NET object that has implemented the COM.
Also in addition to what David, said when using Native API Code in .NET make
sure they will have permissions to run, see below link what i mean.
All this helps you make your .NET app work well with native code, but again
if the native code has issues, have to fix it there.
VJ
"David Browne" <davidbaxterbro wne no potted meat@hotmail.co mwrote in
message news:O%23O%23wR ZaHHA.4508@TK2M SFTNGP03.phx.gb l...
Ok maybe I was not clear on what I said. The IDisposablie if for a .NET
Object not for COM. If the COM has a problem very true you fix it there..,
but any time you use Unmanaged code and reference in a .NET app, please wrap
it in a object with IDisposiable implementation and make sure you call
..Dispose() after done with the .NET object that has implemented the COM.
Also in addition to what David, said when using Native API Code in .NET make
sure they will have permissions to run, see below link what i mean.
All this helps you make your .NET app work well with native code, but again
if the native code has issues, have to fix it there.
VJ
"David Browne" <davidbaxterbro wne no potted meat@hotmail.co mwrote in
message news:O%23O%23wR ZaHHA.4508@TK2M SFTNGP03.phx.gb l...
>
>
"Simon" <simon@nothanks .comwrote in message
news:OcNlsUYaHH A.2076@TK2MSFTN GP04.phx.gbl...
>
Yeah, that's nonsense. If the COM component really has a memory leak, you
would need to fix it in the COM component.
>
However, often .NET code using COM components have poor memory performance
because the Runtime Callable Wrappers that .NET uses to wrap the COM
interface pointers will not destroy the COM component until they are
finalized. This can cause lots of memory problems, although it's not
technically a leak. As a best practice, anytime you are using a COM
component from .NET, explicitly call
System.Runtime. InteropServices .Marshal.Releas eComObject when you are done
with the COM component. This will immediately decrement the reference
count on the COM component and should clean up any unmanaged memory
associated with the component.
>
David
>
>
>
"Simon" <simon@nothanks .comwrote in message
news:OcNlsUYaHH A.2076@TK2MSFTN GP04.phx.gbl...
>Hi VJ
>>
>Thanks for your reply.
>>
>I'm not sure how to "implement IDisposable" on these objects as they
>don't have any such method. The COM objects are part of a third party
>programming API that I have no control over.
>>
>How do I get rid of them if they dont have a Dispose() method or any
>obvious equivelant?
>>
>>
>Thanks for your reply.
>>
>I'm not sure how to "implement IDisposable" on these objects as they
>don't have any such method. The COM objects are part of a third party
>programming API that I have no control over.
>>
>How do I get rid of them if they dont have a Dispose() method or any
>obvious equivelant?
>>
Yeah, that's nonsense. If the COM component really has a memory leak, you
would need to fix it in the COM component.
>
However, often .NET code using COM components have poor memory performance
because the Runtime Callable Wrappers that .NET uses to wrap the COM
interface pointers will not destroy the COM component until they are
finalized. This can cause lots of memory problems, although it's not
technically a leak. As a best practice, anytime you are using a COM
component from .NET, explicitly call
System.Runtime. InteropServices .Marshal.Releas eComObject when you are done
with the COM component. This will immediately decrement the reference
count on the COM component and should clean up any unmanaged memory
associated with the component.
>
David
>
>
Comment