I am having problems accessing a managed object from
unmanaged code. Specifically, I have a .NET forms
application with a web service proxy. The forms
application links to an unmanaged DLL which uses callbacks
to receive data via TCP. The data received in the
callback must be passed to a web service via a web method
provided by the proxy. So the callback (which is
unmanaged code) needs to access the proxy (managed object)
to send the data to the web service. I am able to pass a
pointer to the proxy into the unmanaged callback using
pinning pointers and am able to invoke the web method to
transmit the data. The problem with this approach is that
it results in memory leaks, I assume because the CLR
garbage collection is not taking place in the unmanaged
code. Any suggestions of how to correct this or sample
code for a similar scenario whould be much appreciated.
Sonja Keserovic - 30 Sep 2003 23:06 GMT
Bruce, you are right about GC not tracing unmanaged memory. You are
responsible for taking care of that manually (or in cases of COM objects
we'll make sure they are released appropriately). Do you have similar
working scenario that is unmanaged? What would you do there to release
memory?
In case this is not helpful, could you be more specific about your
managed/unmanaged transition? Is your managed language C# or something
else? Is your unmanaged DLL exposing COM API or flat API? How does callback
signature looks like?
Thanks,
Sonja Keserovic
CLR Program Manager
--------------------
>Content-Class: urn:content-classes:message
>From: "Bruce Farmer" <bfarmer@swri.edu>
[quoted text clipped - 32 lines]
>code. Any suggestions of how to correct this or sample
>code for a similar scenario whould be much appreciated.