I was writing a small procedure to generate random points on the unit sphere. The details are not directly relevant here, but the procedure was as follows.
randspherepts := proc(n::nonnegint, d::posint) 
 local i, p, r; 
 description "Returns co-ords of n random pts on the d-dimensional unit sphere [Knuth, 1998: sect. 3.4.1E]"; 
 uses ArrayTools;
 p:= Matrix(n, d, RandomTools:-Generate('distribution(Normal(0,1))', makeproc=true),datatype='hfloat',order='C_order');
 r:= ElementPower(AddAlongDimension(ElementPower(p,2),2),1/2);  
 seq(ElementDivide(p[i,1..-1],r[i]), i=1..n) 
end proc;
If I understand correctly, there is an extremely small chance that the last line will evoke an error due to division by zero. I reckoned, though, that the chance is so small, it could be ignored. Then I decided to partially test that, using the following code.
testb:= n -> member(0., convert(Vector(n, RandomTools:-Generate('distribution(Normal(0, 1))', makeproc = true)), list));
b:=false: to 1000 do b:= b or testb(10000) end do: b;
What I was not expecting was that this small loop would cause Maple to gradually use over 1 GB, and thereby slowdown my whole computer. Rather, I had assumed that Maple would reuse previously-allocated space or else call gc on occasion. Can someone explain the memory usage? (I am using Maple 11.02 running under Windows XP/SP2.)

Please Wait...