create texture cause memory leak

Repeat to create texture and release, it will lead to a memory leak.

https://devtalk.nvidia.com/default/topic/911464/graphic-driver-memory-leak/#4784574

#include "stdafx.h"
#include <direct.h>
#include <dxgi.h>
#include <d3d11.h>
#include <stdio.h>
#include <iostream>

void verify(HRESULT hr)
{
	if (FAILED(hr))
	{
		std::cout << "error: " << hr << std::endl;
		exit(-1);
	}
}

int main()
{
	IDXGIFactory* pFactory = NULL;
	IDXGIAdapter* pAdapter = NULL;
	ID3D11Device* pDevice = NULL;
	ID3D11DeviceContext* pContext = NULL;
	D3D_FEATURE_LEVEL featureLevels[] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_11_1 };
	verify(::D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, featureLevels, 2, D3D11_SDK_VERSION, &pDevice, NULL, &pContext));
	//verify(::D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_WARP, NULL, 0, featureLevels, 2, D3D11_SDK_VERSION, &pDevice, NULL, &pContext));

	for (auto i = 0; ;++i)
	{
		std::cout << "loop: " << i << std::endl;
		ID3D11Texture2D* pTex = NULL;
		D3D11_TEXTURE2D_DESC desc;
		desc.Usage = D3D11_USAGE_DEFAULT;
		desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
		desc.Width = 1024;
		desc.Height = 1024;
		desc.ArraySize = 1;
		desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
		desc.CPUAccessFlags = 0;
		desc.MipLevels = 1;
		desc.MiscFlags = 0;
		desc.SampleDesc = { 1, 0 };
		verify(pDevice->CreateTexture2D(&desc, NULL, &pTex));
		pTex->Release();
	}
	// todo: release resources
	return 0;
}

nvidia-memleak.zip (8.2 KB)

please help!

Simply insert this line after pTex->Release(); :

pContext->Flush();

see description here: https://msdn.microsoft.com/de-de/library/windows/desktop/ff476425(v=vs.85).aspx
[…]Direct3D11 defers the destruction of objects, an application cannot rely upon objects immediately being destroyed. Calling Flush will destroy any objects whose destruction has been deferred. If an application requires synchronous destruction of an object the application should release all its references, call ID3D11DeviceContext::ClearState, and then call Flush.[…]