# Debug new

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Debug_new
> Markdown URL: https://mediated.wiki/source/Debug_new.md
> Source: https://en.wikipedia.org/wiki/Debug_new
> Source revision: 1064339077
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

{{Short description|Technique in C++ to debug memory issues}}
{{DISPLAYTITLE:Debug_new}}
{{context|date=February 2020}}
'''Debug_new''' refers to a technique in [C++](/source/C%2B%2B) to overload and/or redefine [operator new](/source/operator_new) and [operator delete](/source/operator_delete) in order to intercept the memory allocation and deallocation calls, and thus debug a program for memory usage. It often involves defining a macro named '''DEBUG_NEW''', and makes '''new''' become something like '''new(__FILE__, __LINE__)''' to record the file/line information on allocation. Microsoft [Visual C++](/source/Visual_C%2B%2B) uses this technique in its [Microsoft Foundation Classes](/source/Microsoft_Foundation_Classes). There are some ways to extend this method to avoid using macro redefinition while still able to display the file/line information on some platforms.

There are many inherent limitations to this method. It applies only to C++, and cannot catch [memory leak](/source/memory_leak)s by [C](/source/C_(programming_language)) functions like [malloc](/source/malloc). However, it can be very simple to use and also very fast, when compared to some more complete [memory debugger](/source/memory_debugger) solutions.

==See also==
*[Memory debugger](/source/Memory_debugger)

==External links==
*[http://wyw.dcweb.cn/leakage.htm A Cross-Platform Memory Leak Detector]
*[https://msdn.microsoft.com/en-us/library/tz7sxz99.aspx DEBUG_NEW (MFC)]

Category:Software testing tools
Category:Memory management software
Category:Articles with underscores in the title

---
Adapted from the Wikipedia article [Debug new](https://en.wikipedia.org/wiki/Debug_new) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Debug_new?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
