Skip to content

Rapid memory leak when ID3D12Debug::EnableDebugLayer used with Address Sanitizer (ASAN) #899

@BeamRaceMuppet

Description

@BeamRaceMuppet

When ID3D12Debug::EnableDebugLayer is used with Address Sanitizer (ASAN) a rapid memory leak (over 3GB/minute on my machine) can be observed in many, but not all, D3D12 samples. Affected samples include even the most basic ones:

D3D12HelloTriangle
D3D12HelloTexture

D3D12HelloTriangle hits 10.3GB of Process Memory after running for 3 minutes and usage just keeps growing:

Image

This does not affect all samples though, such as D3D12HelloFrameBuffering, which levels off near 600MB:

Image

I have never observed this problem during years of using D3D11. When ASAN is used in general it is normal to observe an initial process memory growth for perhaps a minute or so but this eventually levels off. ASAN tries to keep around some freed memory for awhile in order to detect use-after-free bugs, but it is not supposed to keep growing unbounded.

To reproduce the issue:

  1. Open the D3D12HelloWorld solution.
  2. Right click on the D3D12HelloTriangle project, select Properties.
  3. Make sure the current Configuration is Debug (top left dropdown).
  4. Under C/C++ -> General set Enable Address Sanitizer to Yes.

Image

  1. Run the project.

Expected behavior: relatively small amount of memory growth that eventually stops.

Observed behavior: rapid unbounded memory growth, multiple gigabytes in minutes.

Disabling this code that enables the D3D12 debug layer allows ASAN to function normally:

// Load the rendering pipeline dependencies.
void D3D12HelloTriangle::LoadPipeline()
{
    UINT dxgiFactoryFlags = 0;

#if defined(_DEBUG)
    // Enable the debug layer (requires the Graphics Tools "optional feature").
    // NOTE: Enabling the debug layer after device creation will invalidate the active device.
    {
        ComPtr<ID3D12Debug> debugController;
        if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&debugController))))
        {
            debugController->EnableDebugLayer();

            // Enable additional debug layers.
            dxgiFactoryFlags |= DXGI_CREATE_FACTORY_DEBUG;
        }
    }
#endif
/* ... */
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions