IHttpUser::DereferenceUser Method

IIS 7.0

Decrements the user internal reference count.

virtual VOID DereferenceUser(
) = 0;

This method takes no parameters.

Classes that implement the IHttpUser interface are thread safe for the ReferenceUser and DereferenceUser methods.

Classes that implement the IHttpUser interface use reference counting that is thread safe for memory management. When an IHttpUser pointer is constructed, the internal reference count (a private member variable) is set to 1. When the ReferenceUser method is called, this reference count is incremented by 1. When the DereferenceUser method is called, this same reference count is decremented by 1. Only when the reference count goes to 0 is the IHttpUser interface removed from the heap. This scheme guarantees that the IHttpUser pointer will not be deleted until the last client of that pointer calls the DereferenceUser method.

The ReferenceUser and DereferenceUser method implementations should be thread safe for an IHttpUser pointer. Implementers should provide only private or protected destructors that are called only when the reference count goes to 0.

Clients should never attempt to cast an IHttpUser interface to a more specific class and then call delete directly; clients should instead call the ReferenceUser method exactly once when a pointer to an IHttpUser interface is retrieved, and then call the DereferenceUser method when the IHttpUser interface will no longer be accessed. You should call the ReferenceUser and DereferenceUser methods as early and as late as possible, respectively, to guarantee that an IHttpUser pointer will be valid on the heap when it is accessed and deleted when it is no longer needed.


The following code example demonstrates a class called MyHttpUser that implements the IHttpUser interface.

// Create a class that implements the IHttpUser interface.
class MyHttpUser : public IHttpUser
    // Create a public constructor.
    // Set the internal reference count to 1.
        m_cRefs = 1;

    // Increment the internal reference count.
    virtual VOID ReferenceUser(VOID)

    // Decrement the internal reference count.
    virtual VOID DereferenceUser(VOID)
        // Decrement the reference count and call delete this
        // if the count is 0.
        if (0 == InterlockedDecrement(&m_cRefs))
            delete this;

    // Create a private destructor called from DereferenceUser.
    virtual ~MyHttpUser()


    //Private reference count member.
    LONG m_cRefs;





  • IIS 7.0 on Windows Vista

  • IIS 7.5 on Windows 7

  • IIS 8.0 on Windows 8

  • IIS 10.0 on Windows 10


  • IIS 7.0 on Windows Server 2008

  • IIS 7.5 on Windows Server 2008 R2

  • IIS 8.0 on Windows Server 2012

  • IIS 8.5 on Windows Server 2012 R2

  • IIS 10.0 on Windows Server 2016 Technical Preview


  • IIS 7.0, IIS 7.5, IIS 8.0, IIS 8.5, IIS 10.0

  • IIS Express 7.5, IIS Express 8.0, IIS Express 10.0