anchor.diff:  end;
   {$ENDIF}
   {$ENDIF DELPHI_XE2_UPE2}
  -
  +//MonitorTryEnter doesn't do a nil check!
  +function SafeMonitorTryEnter(const AObject: TObject): Boolean;
  +begin
  +  if AObject <> nil then
  +    Result := TMonitor.TryEnter(AObject)
  +  else
  +    result := False;
  +end;
   
   
   constructor TWeakReference<T>.Create(const data: T);
   var
  -  weakRef : IWeakReferenceableObject;
  +  target : IWeakReferenceableObject;
     d : IInterface;
  -begin
  +  pInfo : PTypeInfo;
  +begin
  +  inherited Create;
  +  pInfo := TypeInfo(T);
  +
  +  if data = nil then
  +    raise Exception.Create(format('[%s] passed to TWeakReference was nill', [pInfo.Name]));
  +
     d := IInterface(data);
  -  if Supports(d,IWeakReferenceableObject,weakRef) then
  +  if Supports(d,IWeakReferenceableObject,target) then
     begin
  -    FData := d as TObject;
  -    weakRef.AddWeakRef(@FData);
  +    FData := target as TObject;
  +    target.AddWeakRef(@FData);
     end
     else
       raise Exception.Create(SWeakReferenceError);
  
positive.code: 
  function TWeakReferencedObject._AddRef: Integer;
  begin
    Result := TInterlocked.Increment(FRefCount);
  end;
  
  function TWeakReferencedObject._Release: Integer;
  begin
    Result := TInterlocked.Decrement(FRefCount);
    if Result = 0  then
      Destroy;
  end;
  
  
  
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;
  