Let the CRT debug heap detect memory leaks and report on them at program termination. Refer to Find memory leaks with the CRT library
How to check memory leak with code?
D.D.K-2637
966
Reputation points
Hi,
From this post, I want to check for memory leaks. however it still shows the leak.
Am I missing something?
_CrtMemState sOld;
_CrtMemState sNew;
_CrtMemState sDiff;
_CrtMemCheckpoint(&sOld); //take a snapshot
std::wstring f{L"abc"};
_CrtMemCheckpoint(&sNew); //take a snapshot
if (_CrtMemDifference(&sDiff, &sOld, &sNew)) // if there is a difference
{
OutputDebugString(L"-----------_CrtMemDumpStatistics ---------");
_CrtMemDumpStatistics(&sDiff);
OutputDebugString(L"-----------_CrtMemDumpAllObjectsSince ---------");
_CrtMemDumpAllObjectsSince(&sOld);
OutputDebugString(L"-----------_CrtDumpMemoryLeaks ---------");
_CrtDumpMemoryLeaks();
}
Developer technologies | C++
Developer technologies | C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
Answer accepted by question author
1 additional answer
Sort by: Most helpful
-
فاطمة شحات 6 Reputation points2023-05-01T23:53:23.0433333+00:00 هناك أسلوب آخر لتحديد مكان تسرب الذاكرة يتضمن أخذ لقطات من حالة ذاكرة التطبيق في نقاط رئيسية. لأخذ لقطة من حالة الذاكرة في نقطة معينة في التطبيق الخاص بك ، قم بإنشاء بنية
_CrtMemStateوتمريرها إلى_CrtMemCheckpointالوظيفة.