Print this page

Apex max heap size shows as 0 for LIMIT_USAGE_FOR_NS when heap size is not 0

Knowledge Article Number 000220979
Description Why does it show Apex max heap size as 0 for LIMIT_USAGE_FOR_NS when heap size is not 0? 
LIMIT_USAGE_FOR_NS report for Heap Size currently shows as 0, though the used heap size for current apex transaction is more than 0 bytes. This is because the process doesn't walk the heap all the time, and it is expensive to keep the heap calculation for reporting purpose. Generally speaking, the heap size is only reported if it goes beyond 50% of the limit.

Though heap size is reported as 0, the limit is still enforced and will throw error and exit the process when it hits the Maximum allowed Heap size. 

Custom debug message can be added to print the heap size to debug logs.

Example :
System.debug('Current Heap Size: ' + Limits.getHeapSize());

promote demote