MemoryConstrained
✖
MemoryConstrained
Details

- MemoryConstrained generates an interrupt to stop the evaluation of expr if the amount of additional memory requested during the evaluation of expr exceeds b bytes.
- MemoryConstrained evaluates failexpr only if the evaluation is aborted.
- MemoryConstrained returns $Aborted if the evaluation is aborted and no failexpr is specified.
- Aborts generated by MemoryConstrained can be overruled by AbortProtect. »
- MemoryConstrained[expr,Infinity] imposes no memory constraint.
Examples
open allclose allBasic Examples (2)Summary of the most common use cases

https://wolfram.com/xid/0h2iz35kuq-nv2


https://wolfram.com/xid/0h2iz35kuq-ex8

Run a command until a memory limit is exceeded:

https://wolfram.com/xid/0h2iz35kuq-ga4y2k

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

https://wolfram.com/xid/0h2iz35kuq-byzajr

Scope (2)Survey of the scope of standard use cases
Specify the value to return if the time constraint is reached:

https://wolfram.com/xid/0h2iz35kuq-dnbq8p

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

https://wolfram.com/xid/0h2iz35kuq-3ql9m8



Properties & Relations (4)Properties of the function, and connections to other functions
The third argument is only evaluated if the memory limit is reached:

https://wolfram.com/xid/0h2iz35kuq-lieade


https://wolfram.com/xid/0h2iz35kuq-t4m0w9


A nested AbortProtect can block the action of MemoryConstrained:

https://wolfram.com/xid/0h2iz35kuq-rpeft



An enclosing AbortProtect is overridden by MemoryConstrained:

https://wolfram.com/xid/0h2iz35kuq-xd89xl


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

https://wolfram.com/xid/0h2iz35kuq-q6pyqn



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

https://wolfram.com/xid/0h2iz35kuq-vicb1l


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
]}
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
]}