> For the complete documentation index, see [llms.txt](https://learn.mechanic.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learn.mechanic.dev/faq/how-can-i-reduce-memory-usage-of-my-task.md).

# How can I reduce memory usage of my task?

Suggestions for task code that's running out memory

{% hint style="info" %}
Instant fixes are hard to come by for this kind of problem. If you need help with your task code, [here's where to find assistance](/custom-help.md).
{% endhint %}

Memory efficiency is a dynamic problem. Here are some tips for task code when memory constraints become a factor.

## Look for loops.

Any time a data set is iterated upon, any memory inefficiencies within the loop have a chance to be multiplied in severity.

## Look for large assignments.

Remember that Liquid variable assignments (i.e. any use of the [assign tag](/platform/liquid/tags/assign.md)) are always by value, not by reference. This can lead to surprise memory exhaustion with large values. Check on your assignments, concatenations, captures, etc.

## Look for opportunities to split up the work.

A single task run has a limited amount of memory available to it, but you can generate as many task runs as you like. If you need to "fork" into multiple task runs, use [Event actions](/core/actions/event.md) to create events with just enough data to create multiple tightly-scoped task runs.

## Consider bulk operations.

Task runs responding to [mechanic/shopify/bulk\_operation](/core/shopify/bulk-operations.md) are allocated more memory than regular task runs. If you aren't already using one, consider whether your use case could be achieved using a bulk operation.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://learn.mechanic.dev/faq/how-can-i-reduce-memory-usage-of-my-task.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
