---
schema_version: "1"
id: 0940ccc3a25711b0633a6f117c9150e4447588ee8e3fef8fdba23ffc71dc0d8b
title: "ApexGuru Antipattern: Limits.getHeapsize() Methods"
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/xcloud/264-0-0/apexguru_antipattern_limits_getheapsize_methods.md
canonical_url: https://help.salesforce.com/s/articleView?id=xcloud.apexguru_antipattern_limits_getheapsize_methods.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: f15cc9ab5ce2940823682fc783e69c49d230866ee7f708823c55a94f8dc9b951
description: The Limits.getHeapSize() method monitors memory consumption during execution. This operation increases resource consumption, especially when used in production environments. When used in debug statements or logs, this method is evaluated even if the logs aren’t printed in production and this causes more performance degradation.
products:
  - Cross Cloud
release: "264"
---
# ApexGuru Antipattern: Limits.getHeapsize() Methods

The Limits.getHeapSize() method monitors memory consumption during execution. This operation increases resource consumption, especially when used in production environments. When used in debug statements or logs, this method is evaluated even if the logs aren’t printed in production and this causes more performance degradation.

## Scope

Detection and recommendation

## Detection Example

```java
apex
System.debug('Current Heap Size: ' + Limits.getHeapSize());
```

## Recommendation

Avoid using `Limits.getHeapSize()` in production environments unless necessary. Use this method with conditions or remove it if monitoring heap size isn’t required during normal execution.

```java
apex
// Commenting out the Limits.getHeapSize() call in production environments
// System.debug('Current Heap Size: ' + Limits.getHeapSize());
```