# Questions tagged [memory]

Questions about RAM usage, including optimizing memory use, avoiding and fixing leaks and releasing unused memory.

449 questions
Filter by
Sorted by
Tagged with
25 views

### Parallelization with Do and ParallelSubmit

I have quite a large expression that I need to integrate. My ansatz was to Expand the expression (easiest case results in ~5.5 million terms) and parallelize the ...
• 1,419
1 vote
114 views

### Does Mathematica have a function which yields the degree of a polynomial with respect to one variable? [closed]

Since Mathematica seems not to have a function yielding the degree of a polynomial with respect to one variable, I wrote one: ...
• 1,900
65 views

### Mixed Integer Quadratic Program (MIQP): Kernel crashes during computation

I am solving an optimal placement problem using MIQP (Mixed Integer Quadratic Program, using the QuadraticOptimization function WM version 14). The objective ...
• 1
189 views

...
• 1,642
45 views

### Ising Model Simulation Increase Efficiency

I implemented a 2d simulation of Ising Model for zero external magnetic field. Below you can find the function I wrote to calculate the energy (periodic conditions) ...
48 views

### Memory-Efficient FFT of Sparse Array

I have to take the Fourier transform of quite a large 2D array (2^15 by 2^15, but I'll use 2^10 as an example here). My array is mostly zeros, and since Fourier can ...
• 239
60 views

### How can I solve the issue of insufficient memory when dealing with large tuples?

How can I solve the issue of insufficient memory when dealing with large tuples? For example,consider the following example: Tuples[{1, 2, 3}, 25]
• 785
168 views

### 3D FEM Memory Problem with Hexahedral Elements & V14 & Apple Silicon

After using MM V12 for a long time on a MacBook Pro 2011, which just lost 8GB or RAM from 16GB, I am trying V14 on a MacMini M2pro with 32GB. I had previously coded a coupled 3D EM problem involving a ...
• 381
70 views

### Memory leak of coordinate transformation functions with symbolic evaluation

Some functions like ToPolarCoordinates seems not to manage memory usage properly. As is compared to Norm: ...
• 91
1 vote
137 views

### Mathematica builds up RAM usage (how to free memory)

I've already checked this post How to clear up RAM without exiting kernel? But the longer my code works, it builds up RAM and cannot clear it. I've stopped the evaluation and done the following. ...
• 11
67 views

### Mathematica overload memory constructing a matrix

I have the following list of {x,y} positions and I'm trying to connect the neighbors with a distance 1 a.u in a matrix, with the following ...
• 477
71 views

### Is it possible to force ParallelDo to periodically close and launch subkernels?

I have a function f which calls an external library that has a memory leak, so I kind of have to live with it. I call this function thousands of times within ...
• 36.4k
45 views

### Alternatives to Export to write long list as a table on a file

I have a large list (approx 50 millions elements). I could Export it as a table like this: ...
• 6,757
102 views

### How to make the function compile into C faster, and how to determine which portion of the code occupies more memory?

If changing the value of 'n' from 2 to 3 in the above code increases the compilation time from one minute to ten minutes, is there a way to speed it up? Also, the code consumes too much memory during ...
• 161
90 views

### How can I Save function defintion without its DownValues?

I use functions that memorize their values like this one: ...
171 views

### >100 GB of memory used by Reduce. Am I doing something wrong?

Newish to Mathematica here. I'm running some code to compute regions of the parameter space where the covariance between innovations is positive or negative. On my Windows PC, it's been running for ...
77 views

### Memory leak with pure function and in the listable option of compiled function?

I'm using 13.0.0 for Microsoft Windows (64-bit) (December 3, 2021) When I repeatedly run the command ...
• 351
40 views

I use a Dictionary and download it by the command (example Swedish): dict1 = DictionaryLookup[{"Swedish", Repeated[{alfabetet}, {1, Infinity}]}] It downloads and all is well. But when I ...
• 367
423 views

### Is this buggy behavoir of Module solved? [closed]

I have just found out about this bug of Module, i.e. the creation of "zombie"-variables in some cases (see also this post). I couldn't find a post saying ...
• 6,757
152 views

### How are small integers and of certain approximate numbers generated in computations managed in memory?

In the documentation tutorial/SomeNotesOnInternalImplementation, it says: Most raw objects such as strings and numbers are allocated separately; however, unique ...
• 3,740
25 views

### Global time constraint or sandboxing across a notebook?

This may be off-topic, but when accidentally running a process which turns out to be computationally more intensive than expected (or even getting stuck in an infinite loop), it seems that there is ...
• 451
151 views

### How could I see the memory use on sparse array and constant array matrices? What is the advantage? [duplicate]

I have a huge matrix defined using constant array function and it allocates so much memory preventing the calculation. Therefore, I would like to change the constant array matrix into sparse matrix ...
327 views

### Efficient memory usage while building a large sparse matrix

I am sure the following problem has been solved already, but I am unable to find any solution... Any help appreciated! So I am building a pretty huge matrix (or tensor, actually) using ...
152 views

### Why does MemoryInUse keep increasing?

Consider MemoryInUse. After kernel initiation, I have noticed that its value keeps increasing, even when not evaluating any cell, as seen ...
• 4,903
476 views

### Memory leak with Mathematica Graph functions

I am running Mathematica 13.2 on a Mac OS Monterey. I have a large code that manipulates graphs both in graph form and as adjacency matrices, computes some graph properties, and returns a list. It has ...
• 143
47 views

### MMa 13, holding previous solutions instead of clearing them

I suspect this is something one line of code will fix, but I have a fairly simple code, that needs to be evaluated at 2 different points. I tried it for the first one... got an answer, it's correct, ...
• 505
1 vote
40 views

### How to refer to calling notebook instead of my personal include? / detector for high-memory-usage cells

Along the lines of a couple previous posts, I coded this function to show you where in your notebook your biggest space-wasters are. Useful for when your file is becoming huge and unmanageable for ...
• 763
111 views

### Restart kernel after each evaluation in Table

I am trying to integrate a two-dimensional function purely numerically. For one coordinate the integrand can oscillate rapidly while for the other coordinate the integrand is not behaving in a special ...
• 21
1 vote
40 views

### Sorting stored variables in memory

Given the list of stored variables Names@"`*" is it possible to sort them by size in used memory?
• 4,903
119 views

### How to access Shared Memory in Mathematica

I'm running Python code to receive live data stream through web-socket and storing it in the shared memory as the following; ...
• 403
58 views

### MemoryConstrained[] does not work as expected

I am trying to put an upper limit on how much memory the kernel can use. For this, I am using the MemoryConstrained function in Mathematica. But this behaves very weirdly as shown below. ...
• 75
41 views

### What is the best memory utilization and efficiency considerations for simulating particles that are randomly created and removed?

I am wanting to run a simulation involving a varying number of "particles" (points defined by 2D coordinates $(x,y)$ within some region). At each time step, there is a probability that a new ...
• 1,134
92 views

### Controlling memory consumption by memoized function

To speed up a resource-intensive calculation, I use several functions with storing previously calculated values. For example: ...
1 vote
189 views

### How can I prevent Mathematica from filling up memory and crashing my PC when I execute a faulty instruction? [closed]

Sometimes I make a silly mistake and run code that keeps on filling up the memory. Once that is filled, my OS starts page swapping, and there's pretty much nothing I can do except reboot the PC. An ...
• 1,009
62 views

### Parallel image comparison function keeps increasing memory

I have written the following code to align two arbitrary images: ...
• 106
2k views

### What happens if you don't Reap what you've Sown?

As I understand it, when using Sow[expr] you throw the expr on some private stack which you can ...
• 1,620
207 views

### TextRecognize has a memory leak?

This code causes Mathematica to slowly accumulate memory until it hard crashes my operating system. It does this by overwriting OS memory (windows start going black, graphics drivers start crashing ...
• 2,469
122 views

### Improve speed and memory use in the construction of linear combinations of two lists

I have two lists, list1 and list2, for instance ...
• 239
95 views

### Table size/dimension error

I'm trying to create a table of the form ...
105 views

### Does converting large 3D matrices to VERY large 2D matrices affect speed of operations done on the matix?

Novice question! Does the dimensionality of a matrix affect the speed of operations performed on it (or the speed of retrieval of values from it) IF the total number of elements in the matrices are ...
• 185
538 views

### Garbage collection for lexical closures

Mathematica is known not to garbage collect temporary variables in certain cases. I am particularly interested in the very useful programming pattern known as a lexical closure. A somewhat trivial ...
• 11.9k
1 vote
82 views

### Leverage swap space on Linux

Maybe this would be better suited on a different stackexchange, but I'll ask it here anyways in case Mathematica has some inbuilt functionality I'm not aware of. I'm running ...
• 587
305 views

### How to remember evaluation across sessions?

I am performing a very time-consuming symbolic calculation. When I reopen a saved Mathematica notebook, it takes quite a long time to evaluate. Is there an option to tell Mathematica to remember the ...
• 71
1 vote
120 views

### Why Mathematica don't set \$RecursionLimit and \$IterationLimit very big by default? [closed]

For my current program in Mathematica, sometimes I will encounter an error regarding \$IterationLimit and \$RecursionLimit. So I always set these two numbers to very large at the starting of every ...
278 views

### Working around Memory Leak from HermiteDecomposition

I am running into an issue where HermiteDecomposition seems to leak memory, but only from certain matrices ...
• 291
98 views

### Memory problems when fitting large (correlated) datasets

I am trying to fit some complicated function that depends on 18 parameters. The problematic is that I have a large correlated dataset (336 points). When fitting, for simplicity, taking only the ...
• 763
99 views

### JoinAcross Memory Leak

I believe JoinAcross may have a memory leak but would appreciate some help looking at it. It appears to be small when used just once but when iterated a lot it eventually crashes my wolframscripts. I'...
• 592
144 views

### How to optimize ContourPlot3D evaluation?

I tried to plot a certain 3D sine function: ContourPlot3D[(Sin[x^2] + 2) * (Sin[y^2] + 2) * (Sin[z^2] + 2) , {x, -2, 2}, {y, -2, 2}, {z, -2, 2}] but ran into an ...
• 361
109 views

### Free up used Memory

When using FunctionCompile[] to generate a large matrix of ranges there seems to be no way of recovering memory even though the variables are either out of scope or overwritten. I am aware that there ...
• 151