# Avoid error "Failed to allocate String character memory..."?

**URL:** <https://community.wolfram.com/t/avoid-error-failed-to-allocate-string-character-memory/14035>\
**Category:** Questions\
**Tags:** external-interfaces, system-modeler\
**Created:** [May 3, 2019, 4:20pm UTC](https://community.wolfram.com/t/avoid-error-failed-to-allocate-string-character-memory/14035 "2019-05-03T16:20:26Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ericsmith](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/ericsmith/32/2637_2.png) [@ericsmith](https://community.wolfram.com/u/ericsmith)\
**Post date:** [May 3, 2019, 4:20pm UTC](https://community.wolfram.com/t/avoid-error-failed-to-allocate-string-character-memory/14035/1 "2019-05-03T16:20:26Z")

</div>

I’m using the Media library and am getting this error:

> [ERROR]: Failed to allocate String character memory of size 3001 from heap of fixed size 20000000.

No other details that I can see. The model was running and I’m not sure what changed. This is on Wolfram SystemModeler v.12 running on macOS.

EDIT: I switched my Media from CH4 to Air and it worked. I tried other gasses in Media.IdealGases and they all gave the heap error. When I cut the size of my model in half it works fine (both uncoupled halves work).

Not sure there’s enough information to do anything, but any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![henrikt](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/henrikt/32/24544_2.png) [@henrikt](https://community.wolfram.com/u/henrikt)\
**Post date:** [May 6, 2019, 11:32am UTC](https://community.wolfram.com/t/avoid-error-failed-to-allocate-string-character-memory/14035/2 "2019-05-06T11:32:26Z")

</div>

Did you try turning off _Dynamic assert strings_ under _Preferences_ → _General_ → _Translation_?

---

<div class="post-metadata">

**Author:** ![ericsmith](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/ericsmith/32/2637_2.png) [@ericsmith](https://community.wolfram.com/u/ericsmith)\
**Post date:** [May 6, 2019, 12:10pm UTC](https://community.wolfram.com/t/avoid-error-failed-to-allocate-string-character-memory/14035/3 "2019-05-06T12:10:53Z")

</div>

While I didn’t know what it meant, I saw the word “strings” and turned it off and still had the issue. So I did try that, but thanks for the suggestion.

---

<div class="post-metadata">

**Author:** ![ericsmith](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/ericsmith/32/2637_2.png) [@ericsmith](https://community.wolfram.com/u/ericsmith)\
**Post date:** [May 6, 2019, 4:49pm UTC](https://community.wolfram.com/t/avoid-error-failed-to-allocate-string-character-memory/14035/4 "2019-05-06T16:49:03Z")

</div>

I just checked this in Windows (I had found discrepancies between the OS versions in the past). I am getting the same error. It happens with the ideal gas components, but not with Air. I’m going to tag [@Ankit Naik](https://community.wolfram.com/web/ankitn) and [@Jan Brugard](https://community.wolfram.com/web/janb) to see if they have any ideas

---

<div class="post-metadata">

**Author:** ![ericsmith](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/ericsmith/32/2637_2.png) [@ericsmith](https://community.wolfram.com/u/ericsmith)\
**Post date:** [May 6, 2019, 6:26pm UTC](https://community.wolfram.com/t/avoid-error-failed-to-allocate-string-character-memory/14035/5 "2019-05-06T18:26:50Z")

</div>

I turned this off in Simulation Center but not in Model Center. I turned off “Dynamic assert strings” in both places and the error went away. Thank you!

Edit: Tried a larger system and the error came back

---

<div class="post-metadata">

**Author:** ![henrikt](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/henrikt/32/24544_2.png) [@henrikt](https://community.wolfram.com/u/henrikt)\
**Post date:** [May 7, 2019, 9:57am UTC](https://community.wolfram.com/t/avoid-error-failed-to-allocate-string-character-memory/14035/6 "2019-05-07T09:57:19Z")

</div>

OK, it’s good that you can confirm that this is the problem that the _Dynamic assert strings_ setting was meant to address. Then, of course, it’s too bad that it didn’t solve your problems for the larger system. It is a known issue that the user can’t change the size of the memory used to hold strings during expression evaluation, and I’m adding you as a reporter of this.

---

<div class="post-metadata">

**Author:** ![drargento](https://avatars.discourse-cdn.com/v4/letter/d/b2d939/32.png) [@drargento](https://community.wolfram.com/u/drargento)\
**Post date:** [August 30, 2021, 9:40pm UTC](https://community.wolfram.com/t/avoid-error-failed-to-allocate-string-character-memory/14035/7 "2021-08-30T21:40:17Z")

</div>

I am still having this problem with my model. I add/remove one component in a large model and it triggers the error. I can’t find the “Dynamic assert strings” setting in my WSM version (Windows, 12.3). Any suggestions would be appreciated.

---

<div class="post-metadata">

**Author:** ![henrikt](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/henrikt/32/24544_2.png) [@henrikt](https://community.wolfram.com/u/henrikt)\
**Post date:** [August 31, 2021, 7:12am UTC](https://community.wolfram.com/t/avoid-error-failed-to-allocate-string-character-memory/14035/8 "2021-08-31T07:12:04Z")

</div>

The _Dynamic assert strings_ setting was introduced to avoid a performance problem which is now handled using better code generation instead. However, the setting happened to also provide a workaround for hitting the string size constraints in the context of asserts, and for this there is currently no replacement for the setting.

Without knowing more about your particular model, it is not clear whether the problems are related to asserts, or what could be the source of the large strings. To better understand what workarounds one could try or how the product could be improved it would be interesting to know more about your model, such as the type of the added component.

---

<div class="post-metadata">

**Author:** ![drargento](https://avatars.discourse-cdn.com/v4/letter/d/b2d939/32.png) [@drargento](https://community.wolfram.com/u/drargento)\
**Post date:** [August 31, 2021, 5:12pm UTC](https://community.wolfram.com/t/avoid-error-failed-to-allocate-string-character-memory/14035/9 "2021-08-31T17:12:34Z")

</div>

Thank you for the reply. I don’t think there is any calls to “assert” in the code. There are several calls to read/write input and output files. When I commented that out, it runs fine.

---

<div class="post-metadata">

**Author:** ![henrikt](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/henrikt/32/24544_2.png) [@henrikt](https://community.wolfram.com/u/henrikt)\
**Post date:** [September 1, 2021, 5:42am UTC](https://community.wolfram.com/t/avoid-error-failed-to-allocate-string-character-memory/14035/10 "2021-09-01T05:42:31Z")

</div>

I see. System Modeler currently only has basic support for strings, and it sounds as if your approach might require a more complete solution for string handling. If this is the case, it is something we see very rarely – is there any chance that the “heavy” string processing could be lifted also out of your model?

---

<div class="post-metadata">

**Author:** ![drargento](https://avatars.discourse-cdn.com/v4/letter/d/b2d939/32.png) [@drargento](https://community.wolfram.com/u/drargento)\
**Post date:** [September 1, 2021, 5:41pm UTC](https://community.wolfram.com/t/avoid-error-failed-to-allocate-string-character-memory/14035/11 "2021-09-01T17:41:44Z")

</div>

Yes, I removed all that and it is running nicely now.

---

<div class="post-metadata">

**Author:** ![henrikt](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/henrikt/32/24544_2.png) [@henrikt](https://community.wolfram.com/u/henrikt)\
**Post date:** [September 2, 2021, 5:28am UTC](https://community.wolfram.com/t/avoid-error-failed-to-allocate-string-character-memory/14035/12 "2021-09-02T05:28:17Z")

</div>

That’s good to hear. Don’t hesitate to tell us about your application in case you think that the kind of string processing you were doing could be of general interest – requests like that are important for setting the right priorities for future product development.
