<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242737</link>
    <title>MATLAB Central Newsreader - memory usage with plot function</title>
    <description>Feed for thread: memory usage with plot function</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Tue, 20 Jan 2009 12:19:02 -0500</pubDate>
      <title>memory usage with plot function</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242737#622719</link>
      <author>Theodor Zouk</author>
      <description>Hi&lt;br&gt;
I have three questions:&lt;br&gt;
1) Is there a way to see how much memory it takes to plot variables in matlab?&lt;br&gt;
&lt;br&gt;
For example i have the variables:&lt;br&gt;
&lt;br&gt;
y = rand(1,40000000);&lt;br&gt;
x= 0:1/(40000000-1):1;&lt;br&gt;
plot(x,y)&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
2) Why doesn't matlab allways &quot;return&quot; 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... :-/   &lt;br&gt;
&lt;br&gt;
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) &lt;br&gt;
&lt;br&gt;
Im doing the calculation on a Windows XP SP2 32-bit, 3GB RAM. &lt;br&gt;
&lt;br&gt;
Best regards&lt;br&gt;
&lt;br&gt;
Theo</description>
    </item>
    <item>
      <pubDate>Tue, 20 Jan 2009 12:32:06 -0500</pubDate>
      <title>Re: memory usage with plot function</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242737#622723</link>
      <author>vedenev</author>
      <description>Probably you see only real memory usage in Windows Task Manager. Add&lt;br&gt;
vitrual memory column. See both real and vitrual mamory for&lt;br&gt;
MATLAB.exe. It give out of memory usualy when sum is about 3GB.&lt;br&gt;
&lt;br&gt;
When you type clear it is clear not instantly it is need to wait.&lt;br&gt;
&lt;br&gt;
You can claer not all variables. For example &quot;clear a&quot; - clear only a&lt;br&gt;
variable.&lt;br&gt;
&lt;br&gt;
Use saving variables, see functions save and load.&lt;br&gt;
&lt;br&gt;
------------------------------------&lt;br&gt;
Maxim Vedenev, Matlab freelancer&lt;br&gt;
&lt;a href=&quot;http://simulations.narod.ru/&quot;&gt;http://simulations.narod.ru/&lt;/a&gt;</description>
    </item>
    <item>
      <pubDate>Tue, 20 Jan 2009 14:22:26 -0500</pubDate>
      <title>Re: memory usage with plot function</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242737#622747</link>
      <author>Steven Lord</author>
      <description>&lt;br&gt;
&quot;Theodor Zouk&quot; &amp;lt;rebet4@hotmail.com&amp;gt; wrote in message &lt;br&gt;
news:gl4ffm$9u3$1@fred.mathworks.com...&lt;br&gt;
&amp;gt; Hi&lt;br&gt;
&amp;gt; I have three questions:&lt;br&gt;
&amp;gt; 1) Is there a way to see how much memory it takes to plot variables in &lt;br&gt;
&amp;gt; matlab?&lt;br&gt;
&lt;br&gt;
No.&lt;br&gt;
&lt;br&gt;
&amp;gt; For example i have the variables:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; y = rand(1,40000000);&lt;br&gt;
&amp;gt; x= 0:1/(40000000-1):1;&lt;br&gt;
&amp;gt; plot(x,y)&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; these takes 2 x 320 000 000 = 640 MB (double class) to store in the &lt;br&gt;
&amp;gt; memory. When I try to plot them i run out of memory.&lt;br&gt;
&lt;br&gt;
Yes.  The object created by the PLOT function stores the X and Y data used &lt;br&gt;
to create it as the XData and YData properties inside the object.  That &lt;br&gt;
means that when you PLOT, you need four contiguous blocks of 320 MB each --  &lt;br&gt;
two for the x and y variables, and two for the XData and YData properties. &lt;br&gt;
If you don't have two more contiguous blocks of memory, MATLAB will &lt;br&gt;
correctly throw an Out of Memory error.&lt;br&gt;
&lt;br&gt;
Now obviously this is a contrived example.  Two approaches you could use &lt;br&gt;
with your real data would be to resample your data (using INTERP1 or &lt;br&gt;
RESAMPLE) or to plot your data in pieces and only keep around those regions &lt;br&gt;
of interest.&lt;br&gt;
&lt;br&gt;
&amp;gt; 2) Why doesn't matlab allways &quot;return&quot; memory back to operating system &lt;br&gt;
&amp;gt; after using the plot function.&lt;br&gt;
&lt;br&gt;
See above.&lt;br&gt;
&lt;br&gt;
&amp;gt; I.e sometimes i try to plot large variables but runs out of memory, When I &lt;br&gt;
&amp;gt; then CLEAR ALL, Matlab still uses all lot of the memory according to &lt;br&gt;
&amp;gt; Windows Task Manager, and according to FEATURE MEMSTATS my Largest Cont. &lt;br&gt;
&amp;gt; Free Block is only half the size of the biggest block when im first &lt;br&gt;
&amp;gt; initializing Matlab. I have used the CLEAR and PACK function but i can not &lt;br&gt;
&amp;gt; get a bigger Larg.Cont. Free Bloc. The only solution is to restart Matlab &lt;br&gt;
&amp;gt; and thats a realy poor solution according to me... :-/&lt;br&gt;
&lt;br&gt;
If you have the PLOT open, then the best you could do would be to clear the &lt;br&gt;
variables from the workspace.&lt;br&gt;
&lt;br&gt;
&amp;gt; 3) Is there a way to organize the 'Largest Contiguous Free Blocks', I mean &lt;br&gt;
&amp;gt; concatenate/defragmentate/release them somehow, without using PACK &lt;br&gt;
&amp;gt; function( cause it can not run in a script nor a function)&lt;br&gt;
&lt;br&gt;
No.&lt;br&gt;
&lt;br&gt;
&amp;gt; Im doing the calculation on a Windows XP SP2 32-bit, 3GB RAM.&lt;br&gt;
&lt;br&gt;
You should read these documents on the support website:&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/support/tech-notes/1100/1106.html&quot;&gt;http://www.mathworks.com/support/tech-notes/1100/1106.html&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/support/tech-notes/1100/1107.html&quot;&gt;http://www.mathworks.com/support/tech-notes/1100/1107.html&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
If you're not using the 3GB switch, that may help you somewhat; but if &lt;br&gt;
you're going to be performing lots of calculations on large data sets, you &lt;br&gt;
probably want to use a 64-bit OS and a 64-bit version of MATLAB.&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Steve Lord&lt;br&gt;
slord@mathworks.com </description>
    </item>
    <item>
      <pubDate>Tue, 20 Jan 2009 15:48:02 -0500</pubDate>
      <title>Re: memory usage with plot function</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242737#622771</link>
      <author>Theodor Zouk</author>
      <description>&quot;Steven Lord&quot; &amp;lt;slord@mathworks.com&amp;gt; wrote in message &amp;lt;gl4mn2$2jm$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &quot;Theodor Zouk&quot; &amp;lt;rebet4@hotmail.com&amp;gt; wrote in message &lt;br&gt;
&amp;gt; news:gl4ffm$9u3$1@fred.mathworks.com...&lt;br&gt;
&amp;gt; &amp;gt; Hi&lt;br&gt;
&amp;gt; &amp;gt; I have three questions:&lt;br&gt;
&amp;gt; &amp;gt; 1) Is there a way to see how much memory it takes to plot variables in &lt;br&gt;
&amp;gt; &amp;gt; matlab?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; No.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; For example i have the variables:&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; y = rand(1,40000000);&lt;br&gt;
&amp;gt; &amp;gt; x= 0:1/(40000000-1):1;&lt;br&gt;
&amp;gt; &amp;gt; plot(x,y)&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; these takes 2 x 320 000 000 = 640 MB (double class) to store in the &lt;br&gt;
&amp;gt; &amp;gt; memory. When I try to plot them i run out of memory.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Yes.  The object created by the PLOT function stores the X and Y data used &lt;br&gt;
&amp;gt; to create it as the XData and YData properties inside the object.  That &lt;br&gt;
&amp;gt; means that when you PLOT, you need four contiguous blocks of 320 MB each --  &lt;br&gt;
&amp;gt; two for the x and y variables, and two for the XData and YData properties. &lt;br&gt;
&amp;gt; If you don't have two more contiguous blocks of memory, MATLAB will &lt;br&gt;
&amp;gt; correctly throw an Out of Memory error.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Now obviously this is a contrived example.  Two approaches you could use &lt;br&gt;
&amp;gt; with your real data would be to resample your data (using INTERP1 or &lt;br&gt;
&amp;gt; RESAMPLE) or to plot your data in pieces and only keep around those regions &lt;br&gt;
&amp;gt; of interest.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; 2) Why doesn't matlab allways &quot;return&quot; memory back to operating system &lt;br&gt;
&amp;gt; &amp;gt; after using the plot function.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; See above.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; I.e sometimes i try to plot large variables but runs out of memory, When I &lt;br&gt;
&amp;gt; &amp;gt; then CLEAR ALL, Matlab still uses all lot of the memory according to &lt;br&gt;
&amp;gt; &amp;gt; Windows Task Manager, and according to FEATURE MEMSTATS my Largest Cont. &lt;br&gt;
&amp;gt; &amp;gt; Free Block is only half the size of the biggest block when im first &lt;br&gt;
&amp;gt; &amp;gt; initializing Matlab. I have used the CLEAR and PACK function but i can not &lt;br&gt;
&amp;gt; &amp;gt; get a bigger Larg.Cont. Free Bloc. The only solution is to restart Matlab &lt;br&gt;
&amp;gt; &amp;gt; and thats a realy poor solution according to me... :-/&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; If you have the PLOT open, then the best you could do would be to clear the &lt;br&gt;
&amp;gt; variables from the workspace.&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
I forgot to mention that I also used CLOSE for the plot but still matlab is consuming a lot of memory. &lt;br&gt;
&lt;br&gt;
&amp;gt; &amp;gt; 3) Is there a way to organize the 'Largest Contiguous Free Blocks', I mean &lt;br&gt;
&amp;gt; &amp;gt; concatenate/defragmentate/release them somehow, without using PACK &lt;br&gt;
&amp;gt; &amp;gt; function( cause it can not run in a script nor a function)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; No.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Im doing the calculation on a Windows XP SP2 32-bit, 3GB RAM.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; You should read these documents on the support website:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;a href=&quot;http://www.mathworks.com/support/tech-notes/1100/1106.html&quot;&gt;http://www.mathworks.com/support/tech-notes/1100/1106.html&lt;/a&gt;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;a href=&quot;http://www.mathworks.com/support/tech-notes/1100/1107.html&quot;&gt;http://www.mathworks.com/support/tech-notes/1100/1107.html&lt;/a&gt;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; If you're not using the 3GB switch, that may help you somewhat; but if &lt;br&gt;
&amp;gt; you're going to be performing lots of calculations on large data sets, you &lt;br&gt;
&amp;gt; probably want to use a 64-bit OS and a 64-bit version of MATLAB.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; -- &lt;br&gt;
&amp;gt; Steve Lord&lt;br&gt;
&amp;gt; slord@mathworks.com &lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
Thank you for all the information&lt;br&gt;
&lt;br&gt;
best regards &lt;br&gt;
Theo</description>
    </item>
  </channel>
</rss>

