当我声明一个我不使用的向量时泄漏 16 字节的内存
Leak 16 bytes of memory when I declare a vector I don't use
所以在我的 DirectX 演示中,我想创建一个 std::threads 的向量来存储我稍后在程序中创建的任何线程。但是,在创建所述向量后,我意识到我总是泄漏 16 字节的内存。
我决定将其更改为整数向量,以确保不是线程 class 导致了问题;果然,内存泄漏仍然存在。当我注释掉向量的声明(我在其余代码中从未使用过)时,我不再泄漏内存。请注意,这不是指针向量,也不是指针本身。
任何人都可以解释为什么我会出现这种泄漏吗?
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.
这也会在我初始化项目时发生,而不是像大多数泄漏发生时那样在关闭期间发生。设置 _CrtSetBreakAlloc(212);
也不会导致中断发生,所以就这样了。
修复了问题;在我的一个调试会话中,我将 DEMO_APP 的实例设为全局。因此它的析构函数没有在 main 的末尾被调用。关闭函数仍在被调用,所以除了 vector 之外没有其他内存被泄漏。谢谢大家!
所以在我的 DirectX 演示中,我想创建一个 std::threads 的向量来存储我稍后在程序中创建的任何线程。但是,在创建所述向量后,我意识到我总是泄漏 16 字节的内存。
我决定将其更改为整数向量,以确保不是线程 class 导致了问题;果然,内存泄漏仍然存在。当我注释掉向量的声明(我在其余代码中从未使用过)时,我不再泄漏内存。请注意,这不是指针向量,也不是指针本身。
任何人都可以解释为什么我会出现这种泄漏吗?
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.
这也会在我初始化项目时发生,而不是像大多数泄漏发生时那样在关闭期间发生。设置 _CrtSetBreakAlloc(212);
也不会导致中断发生,所以就这样了。
修复了问题;在我的一个调试会话中,我将 DEMO_APP 的实例设为全局。因此它的析构函数没有在 main 的末尾被调用。关闭函数仍在被调用,所以除了 vector 之外没有其他内存被泄漏。谢谢大家!