# My game crashes if it runs too long

**URL:** <https://forum.makecode.com/t/my-game-crashes-if-it-runs-too-long/44347>\
**Category:** Help\
**Created:** [June 4, 2026, 10:20pm UTC](https://forum.makecode.com/t/my-game-crashes-if-it-runs-too-long/44347 "2026-06-04T22:20:31Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![ScriptScraper](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/scriptscraper/32/35438_2.png) [@ScriptScraper](https://forum.makecode.com/u/ScriptScraper)\
**Post date:** [June 4, 2026, 10:20pm UTC](https://forum.makecode.com/t/my-game-crashes-if-it-runs-too-long/44347/1 "2026-06-04T22:20:31Z")

</div>

In my PVZ, after I play for a long time, the game crashes, but it’s not a problem with the code for some reason.

game:

> **[PVZ: Makecode Edition+ (WIP)](https://arcade.makecode.com/S74904-87170-21318-00482)**
>
> The definitive version of PVZ on Makecode Arcade, made by ScriptScraper.

Crash screenshot:

 ![Screenshot 2026-06-03 194801](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/6/5/651384b2e0377c9a1c1b86064f181da35816b4d7.png)

---

<div class="post-metadata">

**Author:** ![Air](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/air/32/26413_2.png) [@Air](https://forum.makecode.com/u/Air)\
**Post date:** [June 5, 2026, 2:22am UTC](https://forum.makecode.com/t/my-game-crashes-if-it-runs-too-long/44347/2 "2026-06-05T02:22:29Z")

</div>

i think it’s because the zombies dont auto destroy at the end, and the build up of the causes the game to lag and then eventually crash

---

<div class="post-metadata">

**Author:** ![redSprite](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/redsprite/32/34262_2.png) [@redSprite](https://forum.makecode.com/u/redSprite)\
**Post date:** [June 5, 2026, 2:25am UTC](https://forum.makecode.com/t/my-game-crashes-if-it-runs-too-long/44347/3 "2026-06-05T02:25:56Z")

</div>

I think it may be the mass production of zombies which leads to the game crash due to so many sprites being present.

---

<div class="post-metadata">

**Author:** ![kirbob](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kirbob/32/34880_2.png) [@kirbob](https://forum.makecode.com/u/kirbob)\
**Post date:** [June 5, 2026, 3:24pm UTC](https://forum.makecode.com/t/my-game-crashes-if-it-runs-too-long/44347/4 "2026-06-05T15:24:14Z")

</div>

so uh u might know me from ur post about this game where i had the picture of the wave of purple zombies, i had my game freeze itself forever. ps (pls add nighttime or wave counter for next update 🙂

---

<div class="post-metadata">

**Author:** ![kirbob](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kirbob/32/34880_2.png) [@kirbob](https://forum.makecode.com/u/kirbob)\
**Post date:** [June 5, 2026, 3:24pm UTC](https://forum.makecode.com/t/my-game-crashes-if-it-runs-too-long/44347/5 "2026-06-05T15:24:18Z")

</div>

maybe try putting zombies on auto destroy

---

<div class="post-metadata">

**Author:** ![ScriptScraper](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/scriptscraper/32/35438_2.png) [@ScriptScraper](https://forum.makecode.com/u/ScriptScraper)\
**Post date:** [June 5, 2026, 4:44pm UTC](https://forum.makecode.com/t/my-game-crashes-if-it-runs-too-long/44347/6 "2026-06-05T16:44:26Z")

</div>

Yep wave counter and multiple levels will be the next update. I think I’ll do the main menu (I already have the music) after that, then finish all the daytime levels and plants. Night should be pretty easy after that

---

<div class="post-metadata">

**Author:** ![VoxelMaster64](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/voxelmaster64/32/32075_2.png) [@VoxelMaster64](https://forum.makecode.com/u/VoxelMaster64)\
**Post date:** [June 5, 2026, 5:17pm UTC](https://forum.makecode.com/t/my-game-crashes-if-it-runs-too-long/44347/7 "2026-06-05T17:17:19Z")

</div>

likely a big game (happens with large games) but @richard

also how long around? does it happen if you do nothing? more info is needed

---

<div class="post-metadata">

**Author:** ![ScriptScraper](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/scriptscraper/32/35438_2.png) [@ScriptScraper](https://forum.makecode.com/u/ScriptScraper)\
**Post date:** [June 5, 2026, 6:18pm UTC](https://forum.makecode.com/t/my-game-crashes-if-it-runs-too-long/44347/8 "2026-06-05T18:18:13Z")

</div>

@richard , could you help me with this? Apparently this happened cause I ran out of memory and it’s a problem with the editor

---

<div class="post-metadata">

**Author:** ![ScriptScraper](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/scriptscraper/32/35438_2.png) [@ScriptScraper](https://forum.makecode.com/u/ScriptScraper)\
**Post date:** [June 5, 2026, 6:23pm UTC](https://forum.makecode.com/t/my-game-crashes-if-it-runs-too-long/44347/9 "2026-06-05T18:23:11Z")

</div>

After roughly 10-15 minutes of playing normally (I didn’t measure the time so that’s just a guess) The thing is, it doesn’t even lag whatsoever, so IDK why it happens

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [June 5, 2026, 6:31pm UTC](https://forum.makecode.com/t/my-game-crashes-if-it-runs-too-long/44347/10 "2026-06-05T18:31:45Z")

</div>

i played for a while and it didn’t crash for me:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/d/3/d3b3ec46357fc076bbd4c6a308ce0dbac1a59089.png)

any other hints on how to reproduce this?

---

<div class="post-metadata">

**Author:** ![Bifrosty](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/bifrosty/32/24819_2.png) [@Bifrosty](https://forum.makecode.com/u/Bifrosty)\
**Post date:** [June 5, 2026, 9:33pm UTC](https://forum.makecode.com/t/my-game-crashes-if-it-runs-too-long/44347/11 "2026-06-05T21:33:24Z")

</div>

Yeah this happens with almost all my games after 30 minutes to an hour of playtime. I think it is a problem on makecode’s end.

---

<div class="post-metadata">

**Author:** ![WoofWoof](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/woofwoof/32/32523_2.png) [@WoofWoof](https://forum.makecode.com/u/WoofWoof)\
**Post date:** [June 5, 2026, 9:40pm UTC](https://forum.makecode.com/t/my-game-crashes-if-it-runs-too-long/44347/12 "2026-06-05T21:40:32Z")

</div>

So I added some code to the On A Button Pressed block:

 ![Screenshot 2026-06-05 at 4.29.37 PM](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/d/7/d7575018a3a7c60827f69c6b3c1c88e31037c309.png)  
To figure out if one of these was getting completely with sprites and well…  
 ![Screenshot 2026-06-05 at 4.28.55 PM](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/9/7/97ccd87691925771086328282b55d12602a09812.png)  
Turns out you need just about 1000 sprites hanging around in an array before the game completely breaks, so that’s neat!  
Anyways, like I explained to you [in your own topic](https://forum.makecode.com/t/plants-vs-zombies-makecode-edition/43654/13), sprites do not get removed from arrays when they die. They still exist. You have to remove them yourself! Instead of making your own variable to keep track of them all, simply use the “array of sprites of kind (sun)” block to keep track of them instead:  
 ![Screenshot 2026-06-05 at 4.38.59 PM](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/3/1/31092b89cd64cd02dff2e3c98057a7aa6063d6f9.png)  
Sprites _do_ get removed from this block when they die, and once there are no more references to a sprite it gets cleared by the garbage collector and cannot hog up all the memory anymore. So just replace your variable with this one, and don’t forget to remove the block that adds them to that currentSun array!

---

<div class="post-metadata">

**Author:** ![ScriptScraper](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/scriptscraper/32/35438_2.png) [@ScriptScraper](https://forum.makecode.com/u/ScriptScraper)\
**Post date:** [June 5, 2026, 9:40pm UTC](https://forum.makecode.com/t/my-game-crashes-if-it-runs-too-long/44347/13 "2026-06-05T21:40:43Z")

</div>

So… @WoofWoof found out why it crashed, in my currentSun array, when a sun is deleted, I FORGOT TO REMOVE IT FROM THE ARRAY. So that meant that after thousands of empty sprites amassed in the array, the editor just kills itself

---

<div class="post-metadata">

**Author:** ![kirbob](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kirbob/32/34880_2.png) [@kirbob](https://forum.makecode.com/u/kirbob)\
**Post date:** [June 5, 2026, 9:55pm UTC](https://forum.makecode.com/t/my-game-crashes-if-it-runs-too-long/44347/14 "2026-06-05T21:55:19Z")

</div>

im still confused what happened to mine

---

<div class="post-metadata">

**Author:** ![ScriptScraper](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/scriptscraper/32/35438_2.png) [@ScriptScraper](https://forum.makecode.com/u/ScriptScraper)\
**Post date:** [June 6, 2026, 4:41am UTC](https://forum.makecode.com/t/my-game-crashes-if-it-runs-too-long/44347/15 "2026-06-06T04:41:44Z")

</div>

Well you said the game froze, so thats probably the hundreds of sprites lagging it out​🤣
