Reputation:
So in my DirectX Demo I wanted to create a vector of std::threads to store any threads I created later in the program. However, upon creating said vector I realized that I was always leaking 16 bytes of memory.
I decided to change it to a vector of integers just to make sure it wasn't the thread class that was causing the issue; sure enough, the memory leaks remained. When I comment out the declaration of the vector (which I never use in the rest of the code) I no longer leak memory. Note that this isn't a vector of pointers nor is it a pointer itself.
Can anyone explain why I'm getting this leak?
class DEMO_APP
{
HINSTANCE application;
WNDPROC appWndProc;
HWND window;
// Interface
ID3D11Device* device;
ID3D11DeviceContext* deviceContext;
IDXGISwapChain* swapChain;
ID3D11RenderTargetView* renderTargetView;
ID3D11DepthStencilView* depthStencilView;
ID3D11DepthStencilState* DSLessEqual;
ID3D11BlendState* blendState;
// Threads
std::vector<int> loadingThreads; // <- Why I can't sleep at night
//std::vector<ID3D11DeviceContext*> deferredContexts;
ID3D11DeviceContext* deferredContext;
Detected memory leaks! Dumping objects -> {212} normal block at 0x0000000C620C1930, 16 bytes long. Data: < > 98 D3 C8 F4 F6 7F 00 00 00 00 00 00 00 00 00 00 Object dump complete.
This also happens when I initialize the project, and not during shutdown like when most leaks occur. Setting _CrtSetBreakAlloc(212);
doesn't cause a break to happen either, so there goes that.
Upvotes: 0
Views: 498
Reputation:
Fixed the issue; during one of my debugging sessions I made the instance of DEMO_APP global. Therefore it's destructor wasn't being called at the end of main. The shutdown function was still being called, so no other memory was being leaked but the vector. Thanks all!
Upvotes: 1