WOLFRAM

evaluates expr, stopping if more than b bytes of memory are requested.

MemoryConstrained[expr,b,failexpr]

returns failexpr if the memory constraint is not met.

Details

Examples

open allclose all

Basic Examples  (2)Summary of the most common use cases

Out[1]=1
Out[2]=2

Run a command until a memory limit is exceeded:

Out[1]=1

The loop ran until memory allocation for the result of Range exceeded the limit:

Out[2]=2

Scope  (2)Survey of the scope of standard use cases

Specify the value to return if the time constraint is reached:

Out[1]=1

Use CheckAbort inside MemoryConstrained to select which parts are skipped if the limit is reached:

Out[1]=1

Properties & Relations  (4)Properties of the function, and connections to other functions

The third argument is only evaluated if the memory limit is reached:

Out[1]=1
Out[2]=2

A nested AbortProtect can block the action of MemoryConstrained:

Out[1]=1

An enclosing AbortProtect is overridden by MemoryConstrained:

Out[1]=1

While code inside the MemoryConstrained is terminated, AbortProtect runs to completion:

Out[2]=2

MemoryConstrained can constrain the first argument of CheckAbort, but not the second:

Out[1]=1
Wolfram Research (1988), MemoryConstrained, Wolfram Language function, https://reference.wolfram.com/language/ref/MemoryConstrained.html (updated 2007).
Wolfram Research (1988), MemoryConstrained, Wolfram Language function, https://reference.wolfram.com/language/ref/MemoryConstrained.html (updated 2007).

Text

Wolfram Research (1988), MemoryConstrained, Wolfram Language function, https://reference.wolfram.com/language/ref/MemoryConstrained.html (updated 2007).

Wolfram Research (1988), MemoryConstrained, Wolfram Language function, https://reference.wolfram.com/language/ref/MemoryConstrained.html (updated 2007).

CMS

Wolfram Language. 1988. "MemoryConstrained." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2007. https://reference.wolfram.com/language/ref/MemoryConstrained.html.

Wolfram Language. 1988. "MemoryConstrained." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2007. https://reference.wolfram.com/language/ref/MemoryConstrained.html.

APA

Wolfram Language. (1988). MemoryConstrained. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/MemoryConstrained.html

Wolfram Language. (1988). MemoryConstrained. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/MemoryConstrained.html

BibTeX

@misc{reference.wolfram_2025_memoryconstrained, author="Wolfram Research", title="{MemoryConstrained}", year="2007", howpublished="\url{https://reference.wolfram.com/language/ref/MemoryConstrained.html}", note=[Accessed: 17-May-2025 ]}

@misc{reference.wolfram_2025_memoryconstrained, author="Wolfram Research", title="{MemoryConstrained}", year="2007", howpublished="\url{https://reference.wolfram.com/language/ref/MemoryConstrained.html}", note=[Accessed: 17-May-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_memoryconstrained, organization={Wolfram Research}, title={MemoryConstrained}, year={2007}, url={https://reference.wolfram.com/language/ref/MemoryConstrained.html}, note=[Accessed: 17-May-2025 ]}

@online{reference.wolfram_2025_memoryconstrained, organization={Wolfram Research}, title={MemoryConstrained}, year={2007}, url={https://reference.wolfram.com/language/ref/MemoryConstrained.html}, note=[Accessed: 17-May-2025 ]}