# Memory Issues

**URL:** <https://community.n8n.io/t/memory-issues/30587>\
**Category:** Questions\
**Tags:** cloud, out-of-memory\
**Created:** [September 17, 2023, 2:15am UTC](https://community.n8n.io/t/memory-issues/30587 "2023-09-17T02:15:10Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zac\_Magee](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/zac_magee/32/26893_2.png) [@Zac\_Magee](https://community.n8n.io/u/Zac_Magee)\
**Post date:** [September 17, 2023, 2:15am UTC](https://community.n8n.io/t/memory-issues/30587/1 "2023-09-17T02:15:10Z")

</div>

## Describe the problem/error/question.

I am using the “Split in batches” Node to break up the amount of items going through the workflow. The workflow performs fine whether I put 50 items or 100 items into the split in batches. It also performs fine no matter the batch size.  
The issue is when the workflow goes through the last iteration and ends at the Split in batches, instead of pushing to the done output, it gives me an error saying it must be out of memory to run.  
It is only once the split in batches detects it has no more batches to run.

I have tried returning from Airtable 100 records with a batch of 50 all the way down to currently returning only 12 from Airtable with a batch size of 2.

Question 1. Is this happening because I am in the testing phase?  
Question 2. How do I stop this from happening?

## What is the error message (if any)?

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/b/4/b47221bf040d2d6a71192672c00f7e7e1f831606.png)

- **Running n8n via (Docker, npm, n8n cloud, desktop app):** Cloud
- **Operating system:** Windows

---

<div class="post-metadata">

**Author:** ![Luke\_Austin](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/luke_austin/32/10505_2.png) [@Luke\_Austin](https://community.n8n.io/u/Luke_Austin)\
**Post date:** [September 17, 2023, 1:49pm UTC](https://community.n8n.io/t/memory-issues/30587/4 "2023-09-17T13:49:00Z")

</div>

Generally, when i have to use split in batches, I’ve found it’s better to run everything in the loop in a sub flow to avoid memory issues.

I recommend doing this via a webhook, and passing any variables/data needed in the body of the webhook call. This keeps everything completely isolated.

---

<div class="post-metadata">

**Author:** ![BramKn](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/bramkn/32/11894_2.png) [@BramKn](https://community.n8n.io/u/BramKn)\
**Post date:** [September 17, 2023, 3:05pm UTC](https://community.n8n.io/t/memory-issues/30587/5 "2023-09-17T15:05:07Z")

</div>

Using a subworkflow should also work fine with the execute workflow node. Just remember to clear the data at the end so it doesnt get passed back to the main workflow

---

<div class="post-metadata">

**Author:** ![Zac\_Magee](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/zac_magee/32/26893_2.png) [@Zac\_Magee](https://community.n8n.io/u/Zac_Magee)\
**Post date:** [September 17, 2023, 9:57pm UTC](https://community.n8n.io/t/memory-issues/30587/6 "2023-09-17T21:57:20Z")

</div>

Thank you for your replies! @Luke_Austin and @BramKn  
How do I do something like that?

So I would send off a webhook to the sub-workflow after the set node that is after the items list? Then once that sub workflow is complete trigger back to this one? and then repeat until complete?

To add more context I am scraping TikTok account feeds in this workflow but I have the same issue when scraping users followers.

---

<div class="post-metadata">

**Author:** ![Zac\_Magee](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/zac_magee/32/26893_2.png) [@Zac\_Magee](https://community.n8n.io/u/Zac_Magee)\
**Post date:** [September 18, 2023, 3:59am UTC](https://community.n8n.io/t/memory-issues/30587/7 "2023-09-18T03:59:00Z")

</div>

So after a bit of experimenting, I was able to split the workflow up but it is not passing the data, I just keep getting the error “Set” node does not exist.

Main Workflow.

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/3/2/3267e04e6eddbbbc8fc74b265f4255e5b30af29f.png)

Sub Workflow.

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/7/9/79b73f29f47b9585fab54d71af4e9278c1b9462d.png)

---

<div class="post-metadata">

**Author:** ![Luke\_Austin](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/luke_austin/32/10505_2.png) [@Luke\_Austin](https://community.n8n.io/u/Luke_Austin)\
**Post date:** [September 18, 2023, 7:53am UTC](https://community.n8n.io/t/memory-issues/30587/8 "2023-09-18T07:53:34Z")

</div>

In that scenario, your data reference will be at:

```auto
{{$('Execute Workflow Trigger').first().json}}

```

(if you want the first item, and are sending 1 at a time. Otherwise you’ll need a more creative solution)

I would suggest you keep the “Split in batches” in the main flow, and run the contents of the loop in the sub flow, which will run once per item, then remove itself from memory. As @BramKn said, make sure you clear the data at the end of each sub flow, so it doesn’t get passed back to the main flow. A set node like this:

At the end of the sub flow will just pass a single item:

“reset”: true

back to your main flow, which should now never run out of memory!

Voila

---

<div class="post-metadata">

**Author:** ![Zac\_Magee](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/zac_magee/32/26893_2.png) [@Zac\_Magee](https://community.n8n.io/u/Zac_Magee)\
**Post date:** [September 18, 2023, 8:54pm UTC](https://community.n8n.io/t/memory-issues/30587/9 "2023-09-18T20:54:47Z")

</div>

@Luke_Austin Thank you very much! I will implement this right now! One final question.  
You mentioned “you’ll need a more creative solution”’

What would a more creative solution look like if I where to send more than 1 at a time? Where would be the best place to look for more information on how to do this?

---

<div class="post-metadata">

**Author:** ![Luke\_Austin](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/luke_austin/32/10505_2.png) [@Luke\_Austin](https://community.n8n.io/u/Luke_Austin)\
**Post date:** [September 19, 2023, 7:56am UTC](https://community.n8n.io/t/memory-issues/30587/10 "2023-09-19T07:56:10Z")

</div>

I suspect you’ll have to be more selective in your queries, if the APIs have an option to return less data (I don’t work with tiktok, but I imagine there’s a lot of metadata in that feed, of which you actually need very little).

You can use

```auto
{{$json}}

```

After the “Execute Workflow Trigger” Node to recieve all the items passed by the “Execute Workflow” node in the main flow, but if there is a lot there, you’ll run into the same memory problem. Remember JSON is not very efficient in terms of memory usage - and what seem slike a small amount of data, when converted to JSON quickly uses up your/cloud system resources. You’d be better using a set node before the “Split in Batches” with “keep only set” ticked, and strip the data down to only what you need, and in that case drastically reduce the amount of memory needed.

---

<div class="post-metadata">

**Author:** ![Zac\_Magee](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/zac_magee/32/26893_2.png) [@Zac\_Magee](https://community.n8n.io/u/Zac_Magee)\
**Post date:** [September 19, 2023, 10:33pm UTC](https://community.n8n.io/t/memory-issues/30587/11 "2023-09-19T22:33:37Z")

</div>

Alright perfect! Thank you very much for your help. After come creative use of the “Set” node and also my first time using the code node it now works flawlessly!

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [September 26, 2023, 10:34pm UTC](https://community.n8n.io/t/memory-issues/30587/12 "2023-09-26T22:34:12Z")

</div>

Closed on September 26, 2023, 10:34pm UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
