Jonas, thank you for your response.<br /><br />I actually think I have discovered my problem: I use "BeginThread" but I do not use "EndThread". I was under the impression that was optional, but from reading some other threads and issues in mantis I can see that failing to call EndThread (ie., just letting the function exit) can orphan the thread handle, at least on linux.<br /><br />To illustrate:<br /><br />----------------------------------------------------------------------<br />program Project1;<br /><br />{$mode objfpc}{$H+}<br /><br />uses<br /> cthreads,<br /> Classes,<br /> SysUtils,<br /> DateUtils;<br /><br />{$R *.res}<br /><br /><br />var<br /> finished : longint;<br /><br />function threadFunc (p : pointer) : ptrint;<br />var<br /> someMem : pointer;<br />begin<br /> Writeln('thread ', longint(p), ' started');<br /> someMem := GetMem(1024*1024);<br /> sleep(100);<br /> FreeMem(someMem);<br /> someMem := nil;<br /> Writeln('thread ', longint(p), ' finished');<br /> InterLockedIncrement(finished);<br /> result := 0;<br /> // EndThread;<br />end;<br /><br />var<br /> i : longint;<br /> secondsToRun : integer;<br /> startTime : TDateTime;<br />begin<br /> finished:=0;<br /> secondsToRun := StrToIntDef(ParamStr(1), 20);<br /> startTime := now;<br /> i := 0;<br /> while(SecondsBetween(now, startTime) < secondsToRun) do begin<br /> BeginThread(@threadFunc, pointer(i));<br /> inc(i);<br /> sleep(50);<br /> end;<br /> while (finished < i) do begin<br /> // do nothing<br /> end;<br /> Writeln(finished);<br />end.<br />----------------------------------------------------------------------<br /><br />Running that program causes the memory reported by "top" to skyrocket. However, if I uncomment the "EndThread" line, memory doesn't go up at all. So basically I just need to go around to any of the functions I pass in to be run by BeginThread and make sure they all explicitly call EndThread.<br /><br />Thanks!<br /><br />-SG