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++
3,972 questions
Accepted answer
1 additional answer
Sort by: Most helpful
-
فاطمة شحات 6 Reputation points
2023-05-01T23:53:23.0433333+00:00 هناك أسلوب آخر لتحديد مكان تسرب الذاكرة يتضمن أخذ لقطات من حالة ذاكرة التطبيق في نقاط رئيسية. لأخذ لقطة من حالة الذاكرة في نقطة معينة في التطبيق الخاص بك ، قم بإنشاء بنية
_CrtMemState
وتمريرها إلى_CrtMemCheckpoint
الوظيفة.