简体   繁体   中英

How can I prevent gnuplot from eating my memory?

I have a set of about 500 files with 33 datapoints.

I am plotting these files using the following gnuplot script

do for [i=1:477] {
   reset
   set label sprintf('Time=%03d s',i) at 0, 0.4
   @png
   infile = sprintf('%d/lineX2_U.xy',i)
   outfile = sprintf('plot%03d.png',i)
   print i," ",infile," ",outfile
   set output outfile
   set xlabel "y [m]"
   set ylabel "u [m/s]"
   set xrange [-1:1]
   set yrange [0:1.2]
   plot infile  with line ls 1
}

where I use this macro

png="set terminal pngcairo size 1800,1800 crop enhanced font \"/usr/share/fonts/truetype/times.ttf,30\" dashlength 2; set termoption linewidth 3"

The problem is, that the memory usage of the system is increasing with time, until gnuplot finishes. Proof:

> while true; do \grep MemFree /proc/meminfo ; sleep 10s; done;
MemFree:         9720956 kB
MemFree:         9121936 kB
MemFree:         8401072 kB
MemFree:         7682248 kB
MemFree:         6963356 kB
MemFree:         6219948 kB
MemFree:         5501612 kB
MemFree:         4758256 kB
MemFree:         4064564 kB
MemFree:         3346416 kB
MemFree:         2651620 kB
MemFree:         1933656 kB
MemFree:         1241644 kB
MemFree:          547836 kB
MemFree:          152200 kB
MemFree:          126396 kB
MemFree:          118232 kB
MemFree:          131612 kB
MemFree:          117760 kB
MemFree:          117936 kB
MemFree:          118368 kB
MemFree:        10934164 kB
MemFree:        10898460 kB
MemFree:        10863592 kB
MemFree:        10822712 kB

Which is monitoring the freely available memory during the execution of the gnuplot script. Of course, running out of memory is very undesired. With and without reset seems to make no difference.

After some tests, I found out that the issue is resolved by omitting the crop option for the pngcairo terminal.

A minimal reproductive script then would be:

set terminal png crop
do for [i=1:500] {
 set output sprintf('plot%03d.png', i)
 plot '+' using 1:(rand(0)) w l
}

How can this memory issue caused by the crop option for the pngcairo terminal be resolved?

Note: I am using gnuplot 4.6

This is a bug in the pngcairo terminal when using the crop option. The minimal example to reproduce this is

set terminal pngcairo size 1000,1000 crop
do for [i=1:500] {
  set output 'plot.png'
  plot x w l
  set output
}

Internally, the structure holding the cropped image was not freed, which led to the memory leak. This becomes apparent when generating many images.

The bug persists in 4.6 patchlevel 3, but was fixed in the development version on 2013-09-09, see #1278 Memory leak with 'pngcairo crop' .

EDIT: It is fixed in patchlevel 4.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM