#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#include "systemclass.h"
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pScmdline, int iCmdshow)
{
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG);
SystemClass* System;
bool result;
// Create the system object.
System = new SystemClass;
if (!System)
{
return 0;
}
// Initialize and run the system object.
result = System->Initialize();
if (result)
{
System->Run();
}
// Shutdown and release the system object.
System->Shutdown();
delete System;
System = 0;
_CrtDumpMemoryLeaks();
return 0;
}
Detected memory leaks!
Dumping objects ->
{213} normal block at 0x007BEA50, 96 bytes long.
Data: <7 0 F r a m e s > 37 00 30 00 46 00 72 00 61 00 6D 00 65 00 73 00
{167} normal block at 0x00741E68, 1 bytes long.
Data: < > CD
{166} normal block at 0x00741E08, 1 bytes long.
Data: < > CD
{156} normal block at 0x0074C0A8, 8 bytes long.
Data: < u > F0 75 E4 00 00 00 00 00
{155} normal block at 0x0074C700, 8 bytes long.
Data: < u > B4 75 E4 00 00 00 00 00
Object dump complete.
The thread 0x69d4 has exited with code 0 (0x0).
The thread 0x5598 has exited with code 0 (0x0).
The thread 0x5d64 has exited with code 0 (0x0).
The thread 0x2ff8 has exited with code 0 (0x0).
The thread 0x3550 has exited with code 0 (0x0).
The thread 0xa04 has exited with code 0 (0x0).
Detected memory leaks!
Dumping objects ->
{167} normal block at 0x00741E68, 1 bytes long.
Data: < > CD
{166} normal block at 0x00741E08, 1 bytes long.
Data: < > CD
Object dump complete.
The program '[1604] gomiDX.exe' has exited with code 0 (0x0).
UPDATES:
FOR: Data: <7 0 F r a m e s > 37 00 30 00 46 00 72 00 61 00 6D 00 65 00 73 00 I defined it from class header and assigned L"" in classNAME::classNAME() that did not appear again as leak.
Tomorrow I will add more details. I suspect I defined some 1 to 8 byte data type out of class constructor. So that cant be DX11 resource. For now just correct if I am mistaken at reporting part of Visual Studio's _CrtDumpMemoryLeaks(); tool.
If you're running in the debugger at the time, it will stop on that allocation.
Backtrack up the stack to find out what pointer gets allocated, then you can figure out how to free it.
In my armNetwork.cpp file I did something very wrong. I don't even know why I did this kind of mistake. I put "!" for ARM_svr(ARMNET_Server class) and ARM_clt (ARMNET_Client class) in IF condition so they were never destroyed.
I tried removing everything from code. So I do not install System inside WinMain.
I did this:
1 2 3 4 5 6 7 8 9 10 11
#include "systemclass.h"
#include "CRT_helper.h" //CRT headers
int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ PSTR pScmdline, _In_ int iCmdshow)
{
//NO CODE HERE
//I removed System class which creates new classes from other cpp files.
//NO CODE HERE
_CrtDumpMemoryLeaks();
return 0;
};
I still get this 8 byte leak. What can be the reason ? I also added systemclass.h file to the end of post
unlikely but cut systemclass.h include too.
if that does not do it, make the same code in a console program, preferably using 2-3 compilers. If they all say the same thing, then your dump leaks function needs to be debugged?
memory leak detectors are notorious for false positives. They are designed to look for things and they find them, whether right or wrong. Its gotten better (the early ones were barely usable, you ran them and then human double checked everything it found which could take forever on a big project). If I ran a program for several hours and had only 8 bytes unaccounted for, I would be satisfied unless it runs on an always up machine that does not have an operating system or one that cleans up. The memory leaks that are big trouble are the ones that drop bytes every time through a loop or loop like cycle (thread, etc). Even if its a little per go, it adds up over time, those weird 'it crashes like clockwork every 2 hours' type bugs. The other big ones are large amounts lost even if only once or twice. Hopefully if you make something that big, you pay extra attention to it.
I removed it and replaced by <Windows.h> and tried to run empty WinMain and yes that did not cause any leak. The problem is when I include "systemclass.h" that leaves 8 bytes I did not get why.
systemclass.h includes also "inputclass.h" and "graphicsclass.h" which may have the memory leak. Can't know for sure without seeing it. You could have a static member that's not being deleted.
still, getting the file with the issue is a start
the only thing it should do in that header if you don't use the class anywhere is the static variables.
I don't know the rules on that, whether your memory leak tool knows to let the statics be destroyed at program end before it checks, or if it loses track of those.
what happens if you make similar static variables in a dummy.h file? Are the static vars messing you up? If they are, I would call that a false positive and ignore it.
ok. you can try to fix that if you wrote the leak detector yourself, or you can ignore it, secure in the knowledge that its a false alarm and that the memory will be recovered as the program goes through its destruction and deallocation process.