Skip to content

Commit

Permalink
Remove Resurrect logic as it shouldn't be needed for .NET 6 and newer.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlaanstra committed Nov 11, 2023
1 parent 0c65b63 commit d5b7249
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 61 deletions.
16 changes: 1 addition & 15 deletions src/WinRT.Runtime/ComWrappersSupport.net5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,6 @@ internal static unsafe InspectableInfo GetInspectableInfo(IntPtr pThis)
// We need to do the same thing for System.Type because there can be multiple WUX.Interop.TypeName's
// for a single System.Type.

// Resurrect IWinRTObject's disposed IObjectReferences, if necessary
if (rcw is IWinRTObject winrtObj)
{
winrtObj.Resurrect();
}

return rcw switch
{
ABI.System.Nullable nt => (T)nt.Value,
Expand Down Expand Up @@ -160,15 +154,7 @@ public static void RegisterObjectForInterface(object obj, IntPtr thisPtr) =>

public static object TryRegisterObjectForInterface(object obj, IntPtr thisPtr)
{
var rcw = ComWrappers.GetOrRegisterObjectForComInstance(thisPtr, CreateObjectFlags.TrackerObject, obj);

// Resurrect IWinRTObject's disposed IObjectReferences, if necessary
var target = rcw is Delegate del ? del.Target : rcw;
if (target is IWinRTObject winrtObj)
{
winrtObj.Resurrect();
}
return rcw;
return ComWrappers.GetOrRegisterObjectForComInstance(thisPtr, CreateObjectFlags.TrackerObject, obj);
}

public static IObjectReference CreateCCWForObject(object obj)
Expand Down
18 changes: 0 additions & 18 deletions src/WinRT.Runtime/IWinRTObject.net5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,23 +184,5 @@ object GetOrCreateTypeHelperData(RuntimeTypeHandle type, Func<object> helperData
{
return AdditionalTypeData.GetOrAdd(type, (type) => helperDataFactory());
}

internal void Resurrect()
{
if (NativeObject.Resurrect())
{
foreach (var cached in QueryInterfaceCache)
{
cached.Value.Resurrect();
}

// Delegates store their agile reference as an additional type data.
// These should be recreated when instances are resurrect.
if (AdditionalTypeData.TryGetValue(typeof(AgileReference).TypeHandle, out var agileObj))
{
AdditionalTypeData.TryUpdate(typeof(AgileReference).TypeHandle, new AgileReference(NativeObject), agileObj);
}
}
}
}
}
28 changes: 0 additions & 28 deletions src/WinRT.Runtime/ObjectReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,22 +287,6 @@ protected virtual void Dispose(bool disposing)
}
}

internal bool Resurrect()
{
lock (_disposedLock)
{
if (!disposed)
{
return false;
}
disposed = false;
ResurrectTrackerSource();
AddRef();
GC.ReRegisterForFinalize(this);
return true;
}
}

protected virtual unsafe void AddRef(bool refFromTrackerSource)
{
Marshal.AddRef(ThisPtr);
Expand Down Expand Up @@ -353,18 +337,6 @@ internal unsafe void ReleaseFromTrackerSource()
}
}

private unsafe void ResurrectTrackerSource()
{
if (ReferenceTrackerPtr != IntPtr.Zero)
{
Marshal.AddRef(ReferenceTrackerPtr);
if (!PreventReleaseFromTrackerSourceOnDispose)
{
ReferenceTracker.AddRefFromTrackerSource(ReferenceTrackerPtr);
}
}
}

private unsafe void DisposeTrackerSource()
{
if (ReferenceTrackerPtr != IntPtr.Zero)
Expand Down

0 comments on commit d5b7249

Please sign in to comment.