Merge pull request #2615 from akoeplinger/fix-perfcounter-free-mem-calculation