clear

Explicitly removes variables from memory to help garbage collection. Use this tag to free up memory after processing large arrays or objects that are no longer needed.

{% json products %}
  [
    { "id": 1, "title": "Product 1" },
    { "id": 2, "title": "Product 2" },
    { "id": 3, "title": "Product 3" }
  ]
{% endjson %}

{% assign product_titles = products | map: "title" %}

{% comment %} Process the data... {% endcomment %}
{% log product_titles %}

{% comment %} Clear variables when no longer needed {% endcomment %}
{% clear products, product_titles %}

{% comment %} Variables are now removed from memory {% endcomment %}
{% log products %}

Results in following output:

Syntax

Parameter
Description

variable_name

Name of the variable to clear

var1, var2, ...

Multiple comma-separated variable names

Use Cases

After processing large CSV files:

After GraphQL pagination:

End of script cleanup:

Notes

  • Removes variables from all scopes (local and global)

  • Sets variable to null before deletion to assist garbage collection

  • No error is thrown if variable doesn't exist

  • Useful for long-running scripts that process large datasets

Last updated