NullReferenceException after __crt_dll_terminate

From: Dmitry Sazonov (sazonov_at_sig.com)
Date: 02/08/05


Date: Tue, 8 Feb 2005 06:07:51 -0800

My managed code calls unmanaded DLL.
I'm calling __crt_dll_initialize(); before any work and
calling __crt_dll_terminate before shutdown of my
application.

Here is a problem. I have managed class, which keep
pointer to unmanaged class. I decided to use Dispoe
pattern and descructor. So, my managed wrapper create and
delete unmanaged class. Everything works fine, until
application shutdown.
I'm calling __crt_dll_terminate. After that GC decide to
call my Finalizer, which tried to delete unmanaged
pointer. But, unmanaged heap already desctucted and I got
an exception.

How can I know what unmanaged heap alive?
thanks.

here is my code:
public __gc class Managed : public System::IDisposable
{
        UnManagedClass* unmamaged;
public:
        Managed() : tick(NULL)
        {
                unmamaged = new UnManagedClass();
        }
        ~Managed()
        {
                Dispose();
        }

        void Dispose()
        {
                if( unmamaged != NULL )
                {
                        delete unmamaged;
                        unmamaged = NULL;
                }
        }
}



Relevant Pages

  • Re: [PATCH] call drv->shutdown at rmmod
    ... |>> At the kexec BOF at OSDL there was some discussion on calling the ... |>> device shutdown method at module remove time, in addition to calling ... The driver was the observation that the primary ... |> whether or not to call shutdown for that particular device. ...
    (Linux-Kernel)
  • Re: How do I kill or break out of a synchronous Socket.Accept() ca
    ... I've tried calling both Closeand/or Shutdown(). ... Socket doesn't have a Dispose(), or I would have tried that too. ...
    (microsoft.public.dotnet.general)
  • Re: Memory Leak Experts!!!!
    ... Implementing the dispose design pattern (i.e. implementing the ... IDisposable interface in .NET and calling .Dispose on your objects) is ... managed code is solely handled by the framework, ... >> Regards, ...
    (microsoft.public.dotnet.framework.performance)
  • Re: Calling MAPI from C++/CLI
    ... of support for calling MAPI methods from managed code. ... to move my code toward calling the Outlook Object Model ... call unmanaged code directly from managed code. ...
    (microsoft.public.win32.programmer.messaging)
  • Re: Thread and desktop
    ... Calling Shell_NotifyIconfrom a thread that has ... AFAIK shells are local to desktop (because windows and hooks are) ... Do all apps across all ... To tell the truth I forgot, but AFAIR everyone get notified (shutdown ...
    (microsoft.public.win32.programmer.kernel)