GetTotalMemoryUsageMb() not correct. Calculating UntrackedMemory Usage

How is the total client memory usage at the top of the F9 console calculated?

I need to calculate/be able to get the Memory usage of the category at the bottom of the F9 memory analyzer, “UntrackedMemory”

Certain exploits add to this memory category and this would work as a detection method against these, as it normally sits at 0 without injecting.

There is not an Enum.DeveloperMemoryTag.Untracked so I can’t directly reference this value. I, therefore, have to get the total memory usage and subtract the memory used by all the other categories.

Except, Stats:GetTotalMemoryUsageMb() does not return the correct total memory value.
If you loop through all the memory tags and get their usage, it returns a value higher than the “total” usage displayed at the top, or gotten through the function.

local Tags = {"Internal", "HttpCache", "Instances", "Signals", "LuaHeap", "Script", "PhysicsCollision", "PhysicsParts", "GraphicsSolidModels", "GraphicsMeshParts", "GraphicsParticles", "GraphicsParts", "GraphicsSpatialHash", "GraphicsTerrain", "GraphicsTexture", "GraphicsTextureCharacter", "Sounds", "StreamingSounds", "TerrainVoxels", "Gui", "Animation", "Navigation"}
local Tracked = 0
	
for i, v in pairs(Tags) do
	Tracked = Tracked + Stats:GetMemoryUsageMbForTag(Enum.DeveloperMemoryTag[v])
 end
local Untracked = Stats:GetTotalMemoryUsageMb() - Tracked

This method does not work for calculating the untracked memory usage, although it would if Stats:GetTotalMemoryUsageMb() returned the correct value.
image

The closest results I have had are from the formula below, and they are still around 10 Mb too inaccurate from the total amount tallied in the track loop.

local Total = Stats:GetTotalMemoryUsageMb() + Tracked - Stats:GetMemoryUsageMbForTag(Enum.DeveloperMemoryTag.Internal)

Someone please enlighten me to why the total memory usage is below the actual amount?

7 Likes