Thread Subject: memory usage with plot function

Subject: memory usage with plot function

From: Theodor Zouk

Date: 20 Jan, 2009 12:19:02

Message: 1 of 4

Hi
I have three questions:
1) Is there a way to see how much memory it takes to plot variables in matlab?

For example i have the variables:

y = rand(1,40000000);
x= 0:1/(40000000-1):1;
plot(x,y)

these takes 2 x 320 000 000 = 640 MB (double class) to store in the memory. When I try to plot them i run out of memory.

2) Why doesn't matlab allways "return" memory back to operating system after using the plot function. I.e sometimes i try to plot large variables but runs out of memory, When I then CLEAR ALL, Matlab still uses all lot of the memory according to Windows Task Manager, and according to FEATURE MEMSTATS my Largest Cont. Free Block is only half the size of the biggest block when im first initializing Matlab. I have used the CLEAR and PACK function but i can not get a bigger Larg.Cont. Free Bloc. The only solution is to restart Matlab and thats a realy poor solution according to me... :-/

3) Is there a way to organize the 'Largest Contiguous Free Blocks', I mean concatenate/defragmentate/release them somehow, without using PACK function( cause it can not run in a script nor a function)

Im doing the calculation on a Windows XP SP2 32-bit, 3GB RAM.

Best regards

Theo

Subject: memory usage with plot function

From: vedenev

Date: 20 Jan, 2009 12:32:06

Message: 2 of 4

Probably you see only real memory usage in Windows Task Manager. Add
vitrual memory column. See both real and vitrual mamory for
MATLAB.exe. It give out of memory usualy when sum is about 3GB.

When you type clear it is clear not instantly it is need to wait.

You can claer not all variables. For example "clear a" - clear only a
variable.

Use saving variables, see functions save and load.

------------------------------------
Maxim Vedenev, Matlab freelancer
http://simulations.narod.ru/

Subject: memory usage with plot function

From: Steven Lord

Date: 20 Jan, 2009 14:22:26

Message: 3 of 4


"Theodor Zouk" <rebet4@hotmail.com> wrote in message
news:gl4ffm$9u3$1@fred.mathworks.com...
> Hi
> I have three questions:
> 1) Is there a way to see how much memory it takes to plot variables in
> matlab?

No.

> For example i have the variables:
>
> y = rand(1,40000000);
> x= 0:1/(40000000-1):1;
> plot(x,y)
>
> these takes 2 x 320 000 000 = 640 MB (double class) to store in the
> memory. When I try to plot them i run out of memory.

Yes. The object created by the PLOT function stores the X and Y data used
to create it as the XData and YData properties inside the object. That
means that when you PLOT, you need four contiguous blocks of 320 MB each --
two for the x and y variables, and two for the XData and YData properties.
If you don't have two more contiguous blocks of memory, MATLAB will
correctly throw an Out of Memory error.

Now obviously this is a contrived example. Two approaches you could use
with your real data would be to resample your data (using INTERP1 or
RESAMPLE) or to plot your data in pieces and only keep around those regions
of interest.

> 2) Why doesn't matlab allways "return" memory back to operating system
> after using the plot function.

See above.

> I.e sometimes i try to plot large variables but runs out of memory, When I
> then CLEAR ALL, Matlab still uses all lot of the memory according to
> Windows Task Manager, and according to FEATURE MEMSTATS my Largest Cont.
> Free Block is only half the size of the biggest block when im first
> initializing Matlab. I have used the CLEAR and PACK function but i can not
> get a bigger Larg.Cont. Free Bloc. The only solution is to restart Matlab
> and thats a realy poor solution according to me... :-/

If you have the PLOT open, then the best you could do would be to clear the
variables from the workspace.

> 3) Is there a way to organize the 'Largest Contiguous Free Blocks', I mean
> concatenate/defragmentate/release them somehow, without using PACK
> function( cause it can not run in a script nor a function)

No.

> Im doing the calculation on a Windows XP SP2 32-bit, 3GB RAM.

You should read these documents on the support website:

http://www.mathworks.com/support/tech-notes/1100/1106.html

http://www.mathworks.com/support/tech-notes/1100/1107.html

If you're not using the 3GB switch, that may help you somewhat; but if
you're going to be performing lots of calculations on large data sets, you
probably want to use a 64-bit OS and a 64-bit version of MATLAB.

--
Steve Lord
slord@mathworks.com

Subject: memory usage with plot function

From: Theodor Zouk

Date: 20 Jan, 2009 15:48:02

Message: 4 of 4

"Steven Lord" <slord@mathworks.com> wrote in message <gl4mn2$2jm$1@fred.mathworks.com>...
>
> "Theodor Zouk" <rebet4@hotmail.com> wrote in message
> news:gl4ffm$9u3$1@fred.mathworks.com...
> > Hi
> > I have three questions:
> > 1) Is there a way to see how much memory it takes to plot variables in
> > matlab?
>
> No.
>
> > For example i have the variables:
> >
> > y = rand(1,40000000);
> > x= 0:1/(40000000-1):1;
> > plot(x,y)
> >
> > these takes 2 x 320 000 000 = 640 MB (double class) to store in the
> > memory. When I try to plot them i run out of memory.
>
> Yes. The object created by the PLOT function stores the X and Y data used
> to create it as the XData and YData properties inside the object. That
> means that when you PLOT, you need four contiguous blocks of 320 MB each --
> two for the x and y variables, and two for the XData and YData properties.
> If you don't have two more contiguous blocks of memory, MATLAB will
> correctly throw an Out of Memory error.
>
> Now obviously this is a contrived example. Two approaches you could use
> with your real data would be to resample your data (using INTERP1 or
> RESAMPLE) or to plot your data in pieces and only keep around those regions
> of interest.
>
> > 2) Why doesn't matlab allways "return" memory back to operating system
> > after using the plot function.
>
> See above.
>
> > I.e sometimes i try to plot large variables but runs out of memory, When I
> > then CLEAR ALL, Matlab still uses all lot of the memory according to
> > Windows Task Manager, and according to FEATURE MEMSTATS my Largest Cont.
> > Free Block is only half the size of the biggest block when im first
> > initializing Matlab. I have used the CLEAR and PACK function but i can not
> > get a bigger Larg.Cont. Free Bloc. The only solution is to restart Matlab
> > and thats a realy poor solution according to me... :-/
>
> If you have the PLOT open, then the best you could do would be to clear the
> variables from the workspace.
>

I forgot to mention that I also used CLOSE for the plot but still matlab is consuming a lot of memory.

> > 3) Is there a way to organize the 'Largest Contiguous Free Blocks', I mean
> > concatenate/defragmentate/release them somehow, without using PACK
> > function( cause it can not run in a script nor a function)
>
> No.
>
> > Im doing the calculation on a Windows XP SP2 32-bit, 3GB RAM.
>
> You should read these documents on the support website:
>
> http://www.mathworks.com/support/tech-notes/1100/1106.html
>
> http://www.mathworks.com/support/tech-notes/1100/1107.html
>
> If you're not using the 3GB switch, that may help you somewhat; but if
> you're going to be performing lots of calculations on large data sets, you
> probably want to use a 64-bit OS and a 64-bit version of MATLAB.
>
> --
> Steve Lord
> slord@mathworks.com
>

Thank you for all the information

best regards
Theo

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com