内存无法在Matlab中释放? [英] memory not freed in matlab?

查看:517
本文介绍了内存无法在Matlab中释放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行对绘图进行动画处理的脚本(模拟水流).一段时间后,我通过执行ctrl-c杀死了循环. 经过几次这样的操作后,我得到了错误:

I am running a script that animates a plot (simulation of a water flow). After a while, I kill the loop by doing ctrl-c. After doing this several times I get the error:

??? Error: Out of memory.

在我开始收到该错误后,每次调用脚本都会生成该错误.
现在,它会在执行我要调用的函数内的任何内容之前发生,即,即使我将行a=1添加为要调用的函数的第一行,我仍然会收到错误并且没有打印输出,因此其中的代码该功能甚至不会执行. 是什么原因造成的?

And after I start receiving that error, every call to my script will generate it.
Now, it happens before anything inside the function that I am calling is executed, i.e even if I add the line a=1 as the first line of the function I am calling, I still get the error and no printout, so the code inside the function doesn't even get executed. What could be causing this?

推荐答案

有几种可能的原因.

  1. 您的脚本很可能会创建一些变量来填充内存.运行

  1. Most likely your script creates some variables that are filling up the memory. Run

clear all

在重新启动脚本之前,清除所有变量,或将脚本更改为函数(函数返回后将自动清除所有临时变量).请注意,这还将清除所有已加载的函数,因此脚本的下一次执行必须再次加载它们,这会使(通常很小的)位执行速度变慢.仅调用clear就足够了.

before restarting the script, so that all the variables are cleared, or change your script to a function (which will automatically erase all temporary variables after the function returns). Note that this also clears all loaded functions, so your next execution of the script has to load them again which will slow down the next execution by a (usually tiny) bit. It may be sufficient to call clear only.

也许您是通过在多个图之间绘制多个图来进行动画处理的(无需先清除轴).因此,您可能用完了Java堆空间.您可以单独关闭打开的数字,也可以运行

Maybe you're animating by plotting several plots over one another (without clearing the axes first). Thus you might run out of Java heap space. You can close the open figures individually, or run

close all

您还可以增加系统上使用Java内存Matlab的数量(请参阅此处的说明)-请注意,该限制通常是相当低的,令人讨厌,因此如果您想输入大量数字.

You can also increase the amount of Java Memory Matlab uses on your system (see instructions here) - note that the limit is generally rather low, annoyingly so if you want to tons of figures.

尤其是如果您运行的是Windows的较旧版本,则可能会导致内存碎片化. Matlab需要连续的可用空间块来分配变量.要检查内存碎片,请运行

Especially if you're running an older version of Windows, you may get your memory fragmented. Matlab needs contiguous blocks of free space to assign variables. To check for memory fragmentation, run

memory

,然后查看最大可能变量大小的数字.如果它远小于所有阵列可用的大小,那么该重新启动Matlab了(我猜如果您使用的Windows版本需要重新启动才能解决此问题,您可能要考虑使用Win7购买一台新计算机) .

and look at the number for the maximum possible variable size. If this is much smaller than the size available for all arrays, it's time to restart Matlab (I guess if you use a Windows version that would require a reboot to fix the problem, you may want to look into getting a new computer with Win7).

这篇关于内存无法在Matlab中释放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆