Listing 1

public __gc class Global: public HttpApplication
{
public:
   static CMapStringToPtr* m_pUnmanagedStorage = NULL;
protected:
   void Application_Start(Object* sender, EventArgs* e)
   {
      // Initialize unmanaged storage
      m_pUnmanagedStorage = new CMapStringToPtr();
   }
   void Session_Start(Object* sender, EventArgs* e)
   {
      CString SessionID = Session->SessionID;

      // Initialize unmanaged notice information
      (*m_pUnmanagedStorage)[SessionID] = new CUltraMax();
   }
   void Session_End(Object* sender, EventArgs* e)
   {
      CString SessionID = Session->SessionID;
      // Dispose unmanaged notice information
      void* pStorage = (*m_pUnmanagedStorage)[SessionID];
      delete (CUltraMax*) pStorage;
      // Remove key
      m_pUnmanagedStorage->RemoveKey(SessionID);
   }
   void Application_End(Object *sender, EventArgs *e)
   {
      CString SessionID;
      void* pStorage = NULL;
      // Free all notices
      for ( POSITION pos = m_pUnmanagedStorage->GetStartPosition();
         pos != NULL; m_pUnmanagedStorage->GetNextAssoc(pos,
         SessionID, pStorage) )
      {
         delete (CUltraMax*) pStorage;
      }
      // Remove all keys
      m_pUnmanagedStorage->RemoveAll();
      // Dispose unmanaged storage
      delete m_pUnmanagedStorage;
   }
};