I realize I must have not conveyed what happens correctly.
The CLR garbage collector collects a managed wrapper
objects even though this managed wrapper object still has
live references.
You told me I should use GC.KeepAlive to prevent this
managed wrapper object from being collected and I tell
you I should not need to give such clues to the GC when
there are live references to that wrapper object.
I agree with everything else you said.
Regards,
Laurent
>news:00d401c37f8d$61c78d90$a101280a@phx.gbl...
>Thanks, Jay.
[quoted text clipped - 131 lines]
>
>.
Laurent,
> I realize I must have not conveyed what happens correctly.
>
> The CLR garbage collector collects a managed wrapper
> objects even though this managed wrapper object still has
> live references.
I understood you created this managed wrapper, then handed it completely off
to unmanaged code (via a delegate/callback?). By completely I mean there is
no longer an actual reference to it from a managed object that you have a
reference to. A circular reference (only) between objects where one gets
handed off to unmanaged code, do not count, as you just surrendered your
managed reference to the objects.
Reading an earlier post, maybe I have the above backwards.
Do you actually maintain a reference to the managed wrapper from managed
code?
Can you post code samples? Enough to get a good feel for what you are
actually doing as I am not following the descriptions (remember a picture
(code) is worth a thousand words).
Thanks
Jay
I realize I must have not conveyed what happens correctly.
The CLR garbage collector collects a managed wrapper
objects even though this managed wrapper object still has
live references.
You told me I should use GC.KeepAlive to prevent this
managed wrapper object from being collected and I tell
you I should not need to give such clues to the GC when
there are live references to that wrapper object.
I agree with everything else you said.
Regards,
Laurent
>-----Original Message-----
>Laurent,
>If you stay within managed code it is automatic memory
management!
>You are mixing managed (C#) & unmanaged (C) code, the
automatic memory
>management is not able to deal with the unmanaged
memory. How is it going to
>know what is going on in the unmanaged code? (unless you
tell it) I hope you
>realized its called unmanaged for a reason.
>
>Hence the need for those three classes to help the
managed memory manager
>out, when handing managed objects off to unmanaged code.
>
[quoted text clipped - 7 lines]
>
>"Laurent Th?rond" <ltherond@Concentual.com> wrote in
message
>news:00d401c37f8d$61c78d90$a101280a@phx.gbl...
>Thanks, Jay.
[quoted text clipped - 44 lines]
>>with a C# object and passes this C# object to a C# user
>>callback. The wrapping C# object is a parameter to the
C#
>>user callback. Even though the C# user callback accesses
>>the wrapping object, the wrapping object is collected,
[quoted text clipped - 27 lines]
>>>
>>>> I have a C library making callbacks to methods of
CLR-
>>>> based objects.
>>>I'm not following you here. Are you saying you have a C
[quoted text clipped - 6 lines]
>>>
>>>I have not tried this, but from Managed code you can
use
>>>System.GC.KeepAlive. to ensure a reference to the
object
>>for the lifetime of
>>>a method.
[quoted text clipped - 13 lines]
>>>>
>>>> I have a C library making callbacks to methods of
CLR-
>>>> based objects.
>>>>
>>>> Because (maybe) these CLR-based callbacks never
appear
>>to
>>>> be invoked from the CLR standpoint, the garbage
>>collector
>>>> assumes it is fine to collect their arguments.
>>>>
>>>> In other words, objects with live references are
being
>>>> collected, even though they are being accessed later
>on
[quoted text clipped - 15 lines]
>
>.