MemoryTracker::~MemoryTracker()
{
	if (peak)
		logPeakMemoryUsage();

	if (amount && !next)
		CurrentMetrics::sub(CurrentMetrics::MemoryTracking, amount);
}
CurrentThread::QueryScope::~QueryScope()
{
    try
    {
        if (log_peak_memory_usage_in_destructor)
            logPeakMemoryUsage();

        CurrentThread::detachQueryIfNotDetached();
    }
    catch (...)
    {
        tryLogCurrentException("CurrentThread", __PRETTY_FUNCTION__);
    }
}