Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
clear all does not free the allocated memory in linux

Subject: clear all does not free the allocated memory in linux

From: siavash daryadel

Date: 27 Sep, 2012 08:03:14

Message: 1 of 5

Hi all,
This question is not new. I've seen it a lot. Mostly for the windows systems. But as far as I know it is still unsolved.
you can find a similar discussion at
http://www.mathworks.com/matlabcentral/newsreader/view_thread/240448

Here is the problem!
I've been running a script requiring a large amount of memory in Matlab (2012b).
In order to save RAM, variables are cleared by a "clear all" command or "clear "variable name"" during my scripts.
But this does not solve anything, since I can tell by the Linux System Monitor that memory is still taken by Matlab (which can exceed 12GB), even if I cleared all variables with a "clear all".

 Memory is only freed if I shut down Matlab and restart it.
Is there any command that really clears all the cache?
Thank you!

Subject: clear all does not free the allocated memory in linux

From: Emil Olsen

Date: 5 Oct, 2012 12:06:07

Message: 2 of 5

"Reza Dadar" wrote in message <k41182$90l$1@newscl01ah.mathworks.com>...
> Hi all,
> This question is not new. I've seen it a lot. Mostly for the windows systems. But as far as I know it is still unsolved.
> you can find a similar discussion at
> http://www.mathworks.com/matlabcentral/newsreader/view_thread/240448
>
> Here is the problem!
> I've been running a script requiring a large amount of memory in Matlab (2012b).
> In order to save RAM, variables are cleared by a "clear all" command or "clear "variable name"" during my scripts.
> But this does not solve anything, since I can tell by the Linux System Monitor that memory is still taken by Matlab (which can exceed 12GB), even if I cleared all variables with a "clear all".
>
> Memory is only freed if I shut down Matlab and restart it.
> Is there any command that really clears all the cache?
> Thank you!

I have a similar problem that seems to be a LOT worse afgter I upgraded to Matlab 2012b:
Windows 7 pro, 32bit running on:
Intel Core 2 Duo CPU, 2.8GZ. 4GB RAM.

Whenever vars are cleared using either clearall, clearvars, clear all hidden etc, the memory available for Matlab single arrays does not increase.
And I run out of memory performing simple tasks.

Any solutions would be appreciated?

Subject: clear all does not free the allocated memory in linux

From: james bejon

Date: 6 Oct, 2012 05:27:10

Message: 3 of 5

Yeah, I encountered a similar thing (on Windows) but never needed to solve it in the end. I guess that by using "who" you could replicate a similar functionality, e.g.,

% Create some variables
x = ones(1000);
y = zeros(1000);
memory

% Clear them
V = who; % <-- this can take regexps as arguments
s = sprint('[%s] = deal([])', sprintf('%s ', X{:}));
eval(s);
memory

Subject: clear all does not free the allocated memory in linux

From: Bruno Luong

Date: 6 Oct, 2012 07:44:14

Message: 4 of 5

FYI "clear all" does not warranty all memory is freed. For example mfile that is locked (see mlock() command).

IIRC, there might be other stuffs such as object/class that can be "locked" too. But I'm not using often OOP.

Time to buy new memory for your computer or rethink about your code if you run into such issue.

Bruno

Subject: clear all does not free the allocated memory in linux

From: Bruno Luong

Date: 6 Oct, 2012 08:16:09

Message: 5 of 5

That having said, IMHO it's unfortunate users can't have access to a list of what occupies the memory.

Bruno

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us