How to free memory of variable on linux

23 ビュー (過去 30 日間)
Fan Li
Fan Li 2018 年 1 月 16 日
編集済み: Fan Li 2018 年 1 月 17 日
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 件のコメント
James Tursa
James Tursa 2018 年 1 月 16 日
What specific functions or operations are you doing with the data?
Fan Li
Fan Li 2018 年 1 月 17 日
編集済み: Fan Li 2018 年 1 月 17 日
Hi James
In general, the functions I used include zeros which is to create large arrays(I have changed double type to single, and there is a multidimensional array), cellfun which is used to hold the data after it is read into matlab (I used the way with fgetl function in this post to read my data with modification
https://uk.mathworks.com/matlabcentral/answers/81115-how-to-read-every-nth-line-with-textscan)
xcorr function and sum function.

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 1 月 16 日
"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.

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by