Connection::~Connection()
    {
        Reset();

        for ( int i = 0; i < m_config.numChannels; ++i )
            YOJIMBO_DELETE( *m_allocator, Channel, m_channel[i] );

        YOJIMBO_DELETE( *m_allocator, SequenceBuffer<ConnectionSentPacketData>, m_sentPackets );
        YOJIMBO_DELETE( *m_allocator, SequenceBuffer<ConnectionReceivedPacketData>, m_receivedPackets );
    }
    void PacketFactory::DestroyPacket( Packet * packet )
    {
        assert( packet );
        if ( !packet )
            return;

#if YOJIMBO_DEBUG_PACKET_LEAKS
        assert( allocated_packets.find( packet ) != allocated_packets.end() );
        allocated_packets.erase( packet );
#endif // #if YOJIMBO_DEBUG_PACKET_LEAKS

        assert( m_numAllocatedPackets > 0 );

        m_numAllocatedPackets--;

        YOJIMBO_DELETE( *m_allocator, Packet, packet );
    }
    BaseTransport::~BaseTransport()
    {
        ClearSendQueue();
        ClearReceiveQueue();

#if YOJIMBO_INSECURE_CONNECT
        m_allocator->Free( m_allPacketTypes );
#endif // #if YOJIMBO_INSECURE_CONNECT
        m_allocator->Free( m_packetTypeIsEncrypted );
        m_allocator->Free( m_packetTypeIsUnencrypted );

        YOJIMBO_DELETE( GetAllocator(), PacketProcessor, m_packetProcessor );

        m_packetFactory = NULL;
#if YOJIMBO_INSECURE_CONNECT
        m_allPacketTypes = NULL;
#endif // #if YOJIMBO_INSECURE_CONNECT
        m_packetTypeIsEncrypted = NULL;
        m_packetTypeIsUnencrypted = NULL;
        m_allocator = NULL;
    }