Sunday, October 02, 2011

memory leaks begone


With the help of Valgrind and some judicious code commenting not unlike a binary search I have tracked down the memory leaks in my code. Why is this important? If my code leaks memory it will crash eventually and installations in a gallery shouldn't crash.

The first graph shows the memory foot print over night taken at 60 second intervals. The spikes happen when the software detects someone there. The second graph shows a more complicated piece that detects users and hand movements. This is a preliminary test but it is looking promising. In this case the spikes are people detected and hand movements. It releases the memory again if it forgets about a user but this only happens after a while.

Here is the bash script I used to record the memory samples: It takes 2 parameters the sleep interval and the process id.


#!/bin/bash
if [ $# -lt 2 ]
then
  echo
  echo "This script needs at least 2 command-line arguments: sleep interval and process id."
  exit 1
fi  
while true; do
   #echo "infinite loops [ hit CTRL+C to stop]"
   ps --no-heading -o rss $2 
   sleep $1
done

I created the graphs by feeding the script results into gnuplot.

No comments: