Jump to content
  • Advertisement
Sign in to follow this  
DarkRonin

How to detect memory leaks in UWP C++

This topic is 592 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys,

 

I have purposely introduced a leak in to my UWP C++ (VS.net 2015) application with the intent of figuring out how to detect leaks on exit.

 

So far, I can't figure out how to detect leaks on exit. The internet seems pretty sparse on that front.

 

Any advice would be greatly appreciated :)

Share this post


Link to post
Share on other sites
Advertisement
Thanks for the help, guys! Some things to check out :)

 

One trick I find really useful is to add the following at the start of your main function:

#ifdef _DEBUG
	// The following code is used for detecting memory leaks. If a memory leak is detected when the application exits,
	// the information will be printed out to the debug output window. Change the -1 in _CrtSetBreakAlloc( -1 ) to the
	// allocation number and run the code again... easy to tell if bits and pieces aren't being cleaned up
	_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
	_CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_DEBUG );

	_CrtSetBreakAlloc( -1 );
#endif
You'll get a list of allocations that haven't been freed up when your program exits, then you just replace the -1 with the allocation number in _CrtSetBreakAlloc() so you can potentially see what was being allocated.
 
This certainly isn't foolproof, but it may help you out.


Wow! I didn't know this would still work under UWP. I use this method a lot in my normal C++ projects.

Thanks again everyone! :) Edited by DarkRonin

Share this post


Link to post
Share on other sites

Wow! I didn't know this would still work under UWP. I use this method a lot in my normal C++ projects.

Hah hah, I can't guarantee that it will - worth a shot though :)

Share this post


Link to post
Share on other sites

 

Wow! I didn't know this would still work under UWP. I use this method a lot in my normal C++ projects.

Hah hah, I can't guarantee that it will - worth a shot though :)

 

 

 

Just gave it a go. Unfortunately it didn't detect any leaks for anything that was created with 'new' but not deleted :(

 

Maybe UWP does some sort of forcible cleanup after an app has ended? I don't really know - LOL.

Share this post


Link to post
Share on other sites

I assume you've tried the basic results from a google search?


You assume correctly. ;)

From the link, it appears that it will catch memory leaks during program execution, which is pretty basic to chase at the best of times. But, I am not seeing how to catch leaks caused by not deleting new'ed classes etc.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!