How to free memory of variable on linux
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi
I wrote a code in matlab, but the input data is 10 GB and also I have to create some very large arrays during calculation which means I need a lot of memory to hold the array. I have read the following suggestions.
https://uk.mathworks.com/help/matlab/large-files-and-big-data.html
In general, the tall array does not support the function I am using. I run the code on linux, so the clear function is not working on the linux. So, apart from changing the double type to single, is there other way to reduce the request memory?
2 comentarios
Respuestas (1)
Walter Roberson
el 16 de En. de 2018
"clear" does work on Linux. It returns the memory for the variable to the MATLAB pool.
MATLAB keeps two memory pools.
One pool is of items of a small and constant size, and is used to hold small variables. Each entire block is given over to a single variable. Because of the constant size, as long as a new item will fit within the block, there is no need to search this pool for blocks that fit the variable.
The other pool is general memory. Objects are allocated as much memory as they need at the time of assignment. The pool might contain a number of blocks of differing available sizes. Available blocks are potentially split. The mechanism used to find an appropriate sized block are not specified and could depend upon the implementation and release -- it could potentially even be left up to the standard C or C++ memory allocation libraries of the compiler that Mathworks is using internally. Memory fragmentation is potentially possible. On MS Windows, somehow memory is (at least under some circumstances) given back to the operating system; I have not figured out how they manage that trick: perhaps it is built in to the memory C/C++ memory allocation libraries they are using on Windows.
If you need finer-grained control over allocation of memory for a matrix, you could consider using https://www.mathworks.com/matlabcentral/fileexchange/28572-sharedmatrix Shared Matrix File Exchange contribution. Although you are not sharing your matrix, the POSIX shared matrix model places the shared memory into an independent memory segment outside of the stack and heap, and so deleting the shared segment gives the memory back to the operating system.
I have, however, seen it said that from R2016b (I think it was) onward that because of internal changes to MATLAB, that MATLAB might crash when the memory is freed for that particular File Exchange contribution. There was a discussion about that a small number of months ago, so I would not be surprised if no-one has happened to find a work-around yet.
0 comentarios
Ver también
Categorías
Más información sobre Whos en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!