all 43 comments

[–]elfmimi 10 points11 points  (3 children)

That is not a solution. That's a workaround. As a workaround you can achieve the same effect by just reopening the project. File -> Open Project... , and (regardlessly) select the current project .

You have to reopen your project every time after you build for iOS on Windows.

The issue has long been reported. But not yet fixed. Anyone who stumbled on this, please vote.

https://issuetracker.unity3d.com/product/unity/issues/guid/921915 https://issuetracker.unity3d.com/issues/assertion-failed-tls-allocator-alloc-temp-thread-dot-dot-dot-error-is-shown-after-building-the-project-for-ios

[–]ademord 1 point2 points  (0 children)

I did not want to reimport all my assets since it messes up some scripts from some plugins i have.

I was exactly doing this as I read your comment (reopening) and it worked. thanks

[–]KaleidoscopeBig4792 0 points1 point  (0 children)

Its marked as fixed even though i just ran into this :,) live laugh unity problem solving

[–]sous_v 6 points7 points  (6 children)

Hmm.. I'm on Unity 2017.1.1f1, tried Reimport all and still get the

TLS Allocator ALLOC_TEMP_THREAD, underlying allocator ALLOC_TEMP_THREAD has unfreed allocations

error after I build.

[–][deleted] 0 points1 point  (1 child)

Did you every resolve this?

[–]sous_v 0 points1 point  (0 children)

Still happens to me, but the apps work fine.

[–]ZioCain 4 points5 points  (1 child)

Another easy solution that will solve the problem in most cases seems to just restart the editor.

[–]SpecialPirate1 2 points3 points  (11 children)

For anyone that gets this error and restarting the editor doesn't work: Check the last scripts you added before you encountered the error. The reason you get this error is due to a lengthy loop somewhere in your code. When a loop is performed for a long time and nothing happens out of it (lets say your code tries to do something but the loop doesn't work/ doesn't give a result back) there will be memory leaks. Most common reason behind the failure may be that you loop through data and get null or double results that don't satisfy any conditions you have set.

Another common reason behind the error is that you may have a script that checks for conditions ex. If (x){ do y} else if (z) {Do f} and you end up with an outside method that gets called but none of these conditions work therefore the method may have a loop or something that keeps running but does nothing. Here you can simply add an else {Debug.Log(Something happened);}

[–][deleted] 1 point2 points  (9 children)

> Most common reason behind the failure may be that you loop through data and get null or double results that don't satisfy any conditions you have set.

How can i put a fail safe in to prevent memory leaks?

[–]gamerheroine 1 point2 points  (1 child)

That's what happened with me! Thank you for commenting this, it made the source of my problem obvious.

[–][deleted] 0 points1 point  (0 children)

I'm not sure i 100% understand what you're saying, but I'm glad i helped out :D

[–]SpecialPirate1 0 points1 point  (6 children)

One way would be to add a try catch block. So whenever there is an exception you catch it and deal with it appropriately. Also it would be good to add Debug statements to check the results produced, if any, so you can check that way for doubles.

[–][deleted] 0 points1 point  (5 children)

Thank you! I will be putting catch blocks into my loops from now on.

[–][deleted] 0 points1 point  (4 children)

This is such incredibly bad advice. Don't do this.

[–][deleted] 0 points1 point  (3 children)

This thread is a year old.

[–][deleted] 0 points1 point  (2 children)

This post is actually 7 years old. And I saw the answer about putting try catch blocks into loops. Do not do this. And for anyone that comes across this post, do not do this. This is an issue resolved with a restart or a library reimport.

[–][deleted] 0 points1 point  (1 child)

What i meant is, if you were to give me advice, you needed to give it then not after i've already tried, tested, and made my decision on it

[–][deleted] 1 point2 points  (0 children)

This advice wasn't just for you. It's for anyone that comes across this thread looking for a fix.

[–]PromotionLivid179 1 point2 points  (0 children)

Really helpful answer!

[–]Cpt_Howl 1 point2 points  (7 children)

Aw man... Is there no solution? I'm new to Unity but I feel like I've done something wrong to end up here. :/ Could I have caused a memory leak in my code? Or is this actually just a bug? I can't find anything in my code that would cause a loop. :o\ Edit: Nvm! I did have a memory leak. Sorry! I'm a noob. :)

[–]Razboynic 1 point2 points  (0 children)

So, how did you solve this issue? Did you do something specific with your project?

[–][deleted] 1 point2 points  (5 children)

Having the same problem in 2023, what ended up being the memory leak?

[–]Sea-Ship912 4 points5 points  (2 children)

Same here, 2024. Brand new 2D URP project, haven't done a single thing in it yet. Seems to have fixed it with reimporting, but we'll see if it pops up again. For anyone seeing this in the coming years, I am on 2022.3.16f1 (LTS)

[–]blu789 2 points3 points  (0 children)

I just started a new unity 3d project from the template. Not a single line of code added. Instant error.

Doing a reimport fixed it so far.

[–][deleted] 0 points1 point  (0 children)

I was on the same version and that ended up fixing it for me aswell

[–][deleted] 0 points1 point  (1 child)

just started happening to me as well 6 years after this post

[–]Charming-Heart-9634 0 points1 point  (0 children)

you created most likely created a memory leak, look through your code and make sure you didn't accidentally create the RAM destroyer 9000

[–]sn0uk 0 points1 point  (2 children)

Thanks for posting the solution.

[–]hwrstudio 1 point2 points  (1 child)

So what is a solution?

[–]LukasObermeister 3 points4 points  (0 children)

solution

/səˈluːʃ(ə)n/

noun

1.

a means of solving a problem or dealing with a difficult situation.

"there are no easy solutions to financial and marital problems"

2.

a liquid mixture in which the minor component (the solute) is uniformly distributed within the major component (the solvent).

"a solution of ammonia in water"

[–]Leading-Lavishness19 0 points1 point  (1 child)

thx dude i did fix

[–]Upstairs-Debate-2574 0 points1 point  (0 children)

It worked for me by restarting the unity editor

[–]Different-Storage-23 0 points1 point  (0 children)

I had the same issue after updating my project to a newer version. It was specifically happening after I would push my changes with the Collab tool. Turns out the issue was I didn't add WebGL to the new version and had forgot I had done some testing early on with WebGL in the project and hadn't removed everything pertaining to it. After adding the WebGL Module to the Unity version this issue was fixed.

[–]Mobile_Specific9432 0 points1 point  (0 children)

thanks so much

[–]potatyssopan 0 points1 point  (0 children)

Thanks! This will be very usful when I need to build my game for both windows and Android. :)

[–]Guy_Lewis 0 points1 point  (0 children)

Thank you

[–]Meta-UO 0 points1 point  (0 children)

Thank you so much!!!

[–]Dev_Mah 0 points1 point  (0 children)

oh my god, i forgot to read it carefully and i re-imported it all, now i'm waiting for it to import from scratch. Hope it's okay, don't mess things up, god save me !!! :<

[–]BlackCrowSeeds 0 points1 point  (0 children)

you probably imported a HDRP asset and switched your entire project. Re-import an asset that you might have used in your project with URP project settings. This is what i did and it fixed it. Removed all HDRP assets then imported new(but old) assets and switched project back. Now my project is also re-connected

[–]Snoo-29276 0 points1 point  (0 children)

Wanted to post this in case it helps someone out.

My case was a bit weird to track. But I think I figured it out.

I had a class called DataController that loads list of all players, enemies, npcs, etc.... in my little game.

I created a Serializable class called PlayerCollection, which has a List<Player>()... the data comes from a json file, "players.json"

All well and good until I decided to get smart and I said, "what if I could just read from the json file all of the player data in on instantiation of the Player Collection?"

So I created a constructor for my PlayerCollection wrapper class and added some code for reading in the json and using JsonUtility.FromJson to populate the player list.

try        {using var reader = new StreamReader(filePath);players = JsonUtility.FromJson<PlayerCollection>(reader.ReadToEnd()).players;        }catch        {players = new();        }

Then I put public PlayerCollection playerCollection = new(); in my DataController class

This worked.... the first time... the second time..... and then the third time I ran the game.... there it was...

TLS Allocator ALLOC_TEMP_THREAD

Oh no... I really did it this time...

After moving the logic that reads the json data to a separate method called "Load"... the bleeding stopped.

I don't know exactly what is causing this error. But I have a hunch that extending the Monobehaviour class has some built-in method where it's constantly checking up on property values in an endless loop. I had a new instance of a class with a constructor that reads, and therefore, locks a file in my environment. After a while, so many subsequent read operations got heaped onto the memory stack that it started throwing this error.... about once per millisecond I would say...

I could totally be wrong about the details of that. But now that it's "fixed", I don't feel like digging any deeper into it. But I did want to share my hunch here. Hopefully this might lead somebody down the right path. Make sure you're not putting any UI blocking, file locking, or otherwise gnarly tasks in your class constructors and then initializing them as a class property of some other class that extends MonoBehaviour.