Closed pierre-quelin closed 1 year ago
I would recommend using void _CrtMemDumpAllObjectsSince(const _CrtMemState *state);
to report more information about the leak.
0 bytes in 0 Free Blocks.
108 bytes in 6 Normal Blocks.
0 bytes in 0 CRT Blocks.
0 bytes in 0 Ignore Blocks.
0 bytes in 0 Client Blocks.
Largest number used: 0 bytes.
Total allocations: 144 bytes.
Dumping objects ->
{2239} normal block at 0x0154C258, 8 bytes long.
Data: <( T > 28 E0 54 01 00 00 00 00
{2238} normal block at 0x0154E028, 28 bytes long.
Data:
That looks to me like it's from the testing infrastructure. If you remove the json
variable, do you get the same result?
Ah, it's probably from the static storage inside those functions that gets initialized on the first use:
static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__;
If that's the case, then this will also result in the exact same 108 byte leak:
test_helpers::MemoryLeakDetector detector;
// json string to enum
json j3 = "running";
assert(j3.get<TaskState>() == TS_RUNNING);
json j4 = "running";
assert(j4.get<TaskState>() == TS_RUNNING);
json j5 = "running";
assert(j5.get<TaskState>() == TS_RUNNING);
and this will result in no leak:
json j3 = "running";
assert(j3.get<TaskState>() == TS_RUNNING);
test_helpers::MemoryLeakDetector detector;
json j4 = "running";
assert(j4.get<TaskState>() == TS_RUNNING);
So this is only a "leak" because the static variables are initialized after the MemoryLeakDetector
and not destroyed until after the detector.
Thank you. I still have to see how to correct my unit test, especially for the user classes.
Description
The basic usage of NLOHMANN_JSON_SERIALIZE_ENUM seems to return an error with _CrtMemCheckpoint Microsoft tool.
Reproduction steps
A basic google test return "Memory leak of 108 byte(s) detected" with the code provided as example.
Expected vs. actual results
Expected no memory leaks vs 108 byte(s).
Minimal code example
Error messages
No response
Compiler and operating system
Microsoft Visual C++ 2019 (Win32), Window10
Library version
v3.11.2
Validation
develop
branch is used.