Giuliano Colla wrote: > Al Boldi ha scritto: > > I played with this some more, and it turns out that not only is > > FreeOnTerminate completely broken but Free only frees the OS-thread > > memory if the thread is still running or is preceded by a WaitFor. This > > is on fpc2.0.2/linux. Maybe this has been fixed in 2.2.0? > > > > Below is the test-code. > > > > Can somebody confirm this on other platforms/fpcVersions. > > I've made some quick tests, with what I have ready at hand and with my > test app. Not so different from yours, except that it allows me more > options. Platform Linux, fpc 2.0.4 and 2.2.0, Lazarus.fixes and Lazarus > trunk latest svn. Widgetset gtk1. > > With fpc 2.0.4, FreeOnTerminate leaks memory whatever I've tried.
Ok, same here. > With fpc 2.2.0, using Synchronize, I've been unable to get rid of memory > leaks if the thread is terminated within an OnClose event. > If the thread is terminated before closing the form, it behaves properly. > > With fpc 2.2.0, if I don't use Synchronize, but rather a message queue > processed by the OnIdle handler, then I don't experience any memory > leak, whatever is the thread termination. > > My conclusion: fpc 2.0.4 has almost certainly some bug on > FreeOnTerminate. In many cases it segfaults, meaning, I guess, that > there's some NilAndFree in place of FreeAndNil :-) > > With fpc 2.2.0 it's harder to tell at first glance, but one would say > that the problem is on Lazarus side, because the fpc rtl Syncronize > provide just a thread safe frame, and leaves all the work to the main > thread loop. > > Synchronize is heavily widgetset dependent. That's why I only report > gtk1 results. With gtk2 I've met inconsistent results from one revision > to the next, with qt synchronize for me doesn't work at all. Ok, synchronize is another problem, which I would like to deal with separately. For now, when you start a thread non-suspended, TThread.Execute(false), can you see the memory increase for your project1 app when checking with top? Then, when you TThread.WaitFor/TThread.Free, does it decrease? And by how much? Below is the simplified console app. Thanks for the feedback! -- Al --- program threadbug; {$mode objfpc}{$H+} uses {$IFDEF UNIX} cthreads, {$ENDIF} Classes { add your units here }; type { TThreadBug } TThreadBug=class(TThread) procedure Execute; override; end; { TThreadBug } procedure TThreadBug.Execute; begin writeln('just ran a thread... done!'); end; var t1:TThreadBug; ans:string; begin t1:=TThreadBug.Create(false); writeln('WaitFor? [y/N]'); readln(ans); if ans='y' then begin t1.WaitFor; writeln('OS thread memory released.'); end else writeln('OS thread memory left dangling.'); t1.Free; writeln('Confirm with top now!'); readln; end. _________________________________________________________________ To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe" as the Subject archives at http://www.lazarus.freepascal.org/mailarchives