G
Guest
Hi all,
I have some code similar to the following:
C#
MyClass mVer = ne w MyClass();
…in a member function
mVar.SendEvent( new Event() );
Managed C++
Ref class MyClass
{
Void SendEvent( Event^ event )
{
// event is collected by the GC during this call... why?
mUnmanagedPtr->SendUnmanagedEvent( event->GetUnmanagedEvent() );
}
}
For some reason the GC thinks its ok to collect the managed event object
before SendUnmanagedEvent returns. Standard scope rules dictate that event is
referenced until the C# mVar.SendEvent function returns. At least that’s my
understanding. Because of this strange behavior I get random crashes when the
GC occasionally collects my events during the call.
Is this a bug? Is my expectation wrong? Am I doing something wrong?
I have some code similar to the following:
C#
MyClass mVer = ne w MyClass();
…in a member function
mVar.SendEvent( new Event() );
Managed C++
Ref class MyClass
{
Void SendEvent( Event^ event )
{
// event is collected by the GC during this call... why?
mUnmanagedPtr->SendUnmanagedEvent( event->GetUnmanagedEvent() );
}
}
For some reason the GC thinks its ok to collect the managed event object
before SendUnmanagedEvent returns. Standard scope rules dictate that event is
referenced until the C# mVar.SendEvent function returns. At least that’s my
understanding. Because of this strange behavior I get random crashes when the
GC occasionally collects my events during the call.
Is this a bug? Is my expectation wrong? Am I doing something wrong?