Skip to content
This repository has been archived by the owner on Mar 30, 2019. It is now read-only.

Commit

Permalink
Fix: Memory leak for D3D11 device when CreateWithSwapChain is used
Browse files Browse the repository at this point in the history
When `CreateWithSwapChain` method is used to create a device, it ends up in a native memory leak, when the device, and all its devices are disposed. This doesn't happen when the device and swap chains are created manually. 

Turns out, this happens due to the extra `AddRefs` that gets called internally. The extra unmanaged memory that ends up leaking can be worked around by casting to `IUnknown` and doing an extra manual release, on the device context. 

Incidentally, it happens to be so that the entire set of code that causes this leak in the first place, is totally redundant, since the `ImmediateContext` and the inner `Device` that are manually force initialized care of themselves already. So, simply removing the unnecessary code fixes this. 

PS: Is there any reason that this code is here in the first place? Hopefully, its just there due to legacy reasons, and I didn't miss something important.
  • Loading branch information
prasannavl authored Oct 8, 2016
1 parent aed636b commit 2253901
Showing 1 changed file with 0 additions and 9 deletions.
9 changes: 0 additions & 9 deletions Source/SharpDX.Direct3D11/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,6 @@ private static void CreateWithSwapChain(Adapter adapter, DriverType driverType,
{
swapChain = new SwapChain(factory, device, swapChainDescription);
}

var context = device.ImmediateContext;

if (context != null)
{
context.Device__ = device;
}

device.ImmediateContext__ = context;
}

/// <summary>
Expand Down

0 comments on commit 2253901

Please sign in to comment.