title: How to free a thread in delphi
body: <p>I have multithreaded application as I ask <a href="https://stackoverflow.com/questions/12575590/why-terminated-property-of-thread-is-set">here</a>.
  I want to terminate the thread, and start a new one when following method is called.</p>
  
  <pre><code>procedure TFRABData.RefreshDataset;
  var
    GridUpdater: TGridUpdater;
  begin
    if Assigned(updaterThread) and (updaterThread &lt;&gt; nil) then
    begin
      updaterThread.Terminate;
    end;
    GridUpdater := TGridUpdater.Create(True);
    GridUpdater.OwnerForm := Self;
    updaterThread := GridUpdater;
    GridUpdater.FreeOnTerminate := False;
    GridUpdater.Start;
    CodeSite.Send('RefreshDataset executed');
  end
  </code></pre>
  
  <p>but, when <code>FreeOnTerminate</code> set to <code>True</code>, I get Access Violation, but when <code>FreeOnTerminate</code> set to <code>False</code>, I get memory leak. How to free the thread? </p>