title: Delphi TThread under ARC (iOS) not being released
body: <p>What is a proper way to terminate a thread using Delphi for iOS under ARC management?</p>
  
  <p>Take this simple example:</p>
  
  <pre><code>  TMyThread = class(TThread)
    protected
      procedure Execute; override;
    public
      destructor Destroy; override;
    end;
  
    TForm2 = class(TForm)
      Button1: TButton;
      Button2: TButton;
      Button3: TButton;
      procedure Button1Click(Sender: TObject);
      procedure Button2Click(Sender: TObject);
      procedure Button3Click(Sender: TObject);
    private
      FThread: TMyThread;
    public
    end;
  
  { TMyThread }
  destructor TMyThread.Destroy;
  begin
  
    ShowMessage('Destroy');
  
    inherited Destroy;
  
  end;
  
  procedure TMyThread.Execute;
  begin
  
    Sleep(5000);
  
  end;
  
  { TForm2 }
  procedure TForm2.Button1Click(Sender: TObject);
  begin
    FThread := TMyThread.Create(TRUE);
    FThread.FreeOnTerminate := TRUE;
    FThread.Start;
  end;
  
  procedure TForm2.Button2Click(Sender: TObject);
  begin
    ShowMessage(FThread.RefCount.ToString);
  end;
  
  procedure TForm2.Button3Click(Sender: TObject);
  begin
    FThread := nil;
  end;
  </code></pre>
  
  <p>Ok, pressing Button1 will spawn a thread. After thread is started, if you click Button2 it will display a RefCount value of 3!! Well, 1 is the reference to my FThread variable, and there are 2 additional references that TThread creates internally... I have digged into source code and found that RefCount is increased here:</p>
  
  <pre><code>constructor TThread.Create(CreateSuspended: Boolean);
  
    ErrCode := BeginThread(nil, @ThreadProc, Pointer(Self), FThreadID);
    if ErrCode &lt;&gt; 0 then
      raise EThread.CreateResFmt(@SThreadCreateError, [SysErrorMessage(ErrCode)]);
    {$ENDIF POSIX}
  </code></pre>
  
  <p>And here:</p>
  
  <pre><code>function ThreadProc(Thread: TThread): Integer;
  var
    FreeThread: Boolean;
  begin
    TThread.FCurrentThread := Thread;
  </code></pre>
  
  <p>Well... After thread is finished (In my case, after 5 seconds), the RefCount will decrease to 2 (Because I have set FreeOnTerminate to TRUE, but if I don´t set FreeOnTerminate to TRUE, the RefCount will still be 3).</p>
  
  <p>See the problem? Thread is never finished and destructor is never called, if I call <code>FThread := nil</code>, then, the RefCount should decrease from 2 to 1 (Or from 3 to 2 in case <code>FreeOnTerminate = FALSE</code>), and thread is never released under ARC...</p>
  
  <p>Maybe I´m missing something because I´m used to working with threads with no ARC... So, what am I missing here? Or is there a bug in TThread implementation under ARC?</p>
  
  <p>Maybe this definition of TThread</p>
  
  <pre><code>private class threadvar
    FCurrentThread: TThread;
  </code></pre>
  
  <p>should be something like</p>
  
  <pre><code>private class threadvar
    [Weak] FCurrentThread: TThread;
  </code></pre>