anchor.diff:  
   function TWeakReferencedObject._AddRef: Integer;
   begin
  +  if FDestroyed then
  +    raise Exception.Create('_Addref called when Object already destroyed!');
     Result := TInterlocked.Increment(FRefCount);
   end;
   
   function TWeakReferencedObject._Release: Integer;
   begin
  +  if FDestroyed then
  +    raise Exception.Create('_Release called when Object already destroyed!');
     Result := TInterlocked.Decrement(FRefCount);
  -  if Result = 0  then
  +  if (Result = 0) and (not FDestroying) then
  +  begin
  +    FDestroying := True;
       Destroy;
  +  end;
   end;
   
   
  
positive.code: interface
  
  {$I DUnitX.inc}
  
  type
    /// Implemented by our weak referenced object base class
  
negative.code: { TWeakReferencedObject }
  
  procedure TWeakReferencedObject.AddWeakRef(value: Pointer);
  begin
    MonitorEnter(Self);
    try
      if FWeakReferences = nil then
        FWeakReferences := TList<Pointer>.Create;
      FWeakReferences.Add(value);
    finally
      MonitorExit(Self);
    end;
  end;
  
  procedure TWeakReferencedObject.RemoveWeakRef(value: Pointer);
  begin
    MonitorEnter(Self);
    try
      if FWeakReferences = nil then // should never happen
        {$IFDEF DEBUG}
        raise Exception.Create('FWeakReferences = nil');
        {$ELSE}
        exit;
        {$ENDIF}
      FWeakReferences.Remove(value);
      if FWeakReferences.Count = 0 then
        FreeAndNil(FWeakReferences);
    finally
      MonitorExit(Self);
    end;
  end;
  
  procedure TWeakReferencedObject.AfterConstruction;
  begin
    // Release the constructor's implicit refcount
    TInterlocked.Decrement(FRefCount);
    //spin for short period of time before
    TMonitor.SetSpinCount(Self, 200); //default is 1000
  end;
  
  procedure TWeakReferencedObject.BeforeDestruction;
  var
    value : pointer;
    i: Integer;
  begin
    if FRefCount <> 0 then
      System.Error(reInvalidPtr);
    MonitorEnter(Self);
    try
      if FWeakReferences <> nil then
      begin
        for i := 0 to FWeakReferences.Count -1 do
        begin
          value := FWeakReferences.Items[i];
          TObject(value^) := nil;
        end;
          FreeAndNil(FWeakReferences);
      end;
    finally
      MonitorExit(Self);
    end;
    inherited;
  end;
  
  destructor TWeakReferencedObject.Destroy;
  begin
    if FDestroyed then
      raise Exception.Create('Destroy called when Object already destroyed!');
    FDestroyed := true;
    inherited;
  end;
  
  function TWeakReferencedObject.GetRefCount: integer;
  