Memory leak from plotting?
2 次查看(过去 30 天)
显示 更早的评论
In Ubuntu 12.04 64-bit, matlab 2014a, I'd like to be able to plot thousands of lines over several minutes on the same plot (there are several plots total), without running out of memory. Currently, matlab slows way down after about ten seconds as more lines are added. It never crashes but just bogs down.
I can use 'cla', which clears all the axes and also removes prior drawn graphics objects. Same with 'cla reset' which removes objects and resets axes. Is there any way to accumulate many graphics objects without using up too much memory, eg turn it into a bitmap etc? Basically i want to see the evolution of the plots dynamically.
0 个评论
回答(2 个)
dpb
2014-8-7
Don't keep making new objects; there's where the overhead is. See the doc's for guidelines on animating plots at http://www.mathworks.com/help/matlab/creating_plots/animation.html#brb6lra
0 个评论
John
2014-8-7
3 个评论
dpb
2014-8-8
编辑:dpb
2014-8-8
Hmmmm....I thought could do the following--
hL=plot(rand(1,10); % a line
set(h,'ydata',[get(h,'ydata');rand(1,10)])
and get second set for essentially free. But, I was remembering wrong, sorry.
Guess best you can do is to create new line handle for every line and that undoubtedly will begin to slow stuff down as the number increases. Least overhead I know would be
plot(x,y);
hold on
line(x2,y2)
Saving the handles would let you then keep some number and then use a circular buffer to only keep the N latest or the like...
ADDENDUM
A thought; don't know how well it would work in practice -- try allocating an array of LxN where L is length of each series and N is number of lines you think you want to try to plot. Use nan(L,N) for this instead of zeros, however. Then, before the first call to plot, fill the first column with "real" data and plot the array. The data will be allocated in the XYZData arrays, but the NaN values won't be visible. THEN, however, you can populate the next column of the handle arrays each subsequent call.
plot will still create the N line handles and if N is too big you may simply be at the limits of what you can do with Malab handle graphics, but the rest should be as little overhead as is possible if you can get the one initial creation step completed.
BTW, be sure you're not plotting way more data than can possibly be resolved on the screen -- if you've got a big monitor you've probably still got 2000 or so pixels, max. So, if you're plotting much more than that, only a diminishing fraction can be displayed uniquely, the rest are all mushed on top of each other. The moral is decimate to about the same length as there are number of pixels in the display to maximize the information viewable at minimum memory overhead.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!