Jump to content
  • Advertisement
Sign in to follow this  

Problem overloading new and delete

This topic is 3786 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

Hello everyone! I'm trying to overload the global new and delete for debugging purposes, but something is not working quite right. Today I found what I thought to be a memory leak, but after a more careful debugging session, I think in some cases my overloaded delete just doesn't get called. I'm sure it's crammed full with bugs, so I post some code:
//Prototypes included by the precompiled header
#include <cstddef>

void* operator new ( std::size_t sz ); //Uses std::malloc(sz) internally
void operator delete ( void* ptr ); //Uses STD::free(ptr) internally

The problem seems to be localized here:
void CGigaPaq::m_Dispose() {

	//PAQ_HEADER* m_lpphHead, struct PAQ_HEADER
	if (m_lpphHead) {
		delete m_lpphHead;
		m_lpphHead = 0;

	//PAQ_ITEM* lppiFileList, struct PAQ_ITEM
	if (m_lppiFileList) {
		delete[] m_lppiFileList;
		m_lppiFileList = 0;

	//CIOFile* m_lpioPaq, class CIOFile
	if (m_lpioPaq) {
		delete m_lpioPaq;
		m_lpioPaq = 0;


There Are a few things I don't really understand: either in Visual Studio .net and CodeWarrior, my overloaded version of new is always called (even for arrays). The same is true for delete and delete[], which both seem to call my overloaded delete. But in this special case, neither for m_lppiFileList nor for m_lpioPaq delete gets called. The debugger - instead - takes me to a standard delete function from Visual Studio. Thus the apparent memory leak. I've been searching the net for a while, but I've found nothing that looks like this... Any ideas? Edit: If I actually try to implement overloaded versions for new[] and delete[], I get a multiple definition error: Linking... dlDebugInfo.obj : error LNK2005: "void * __cdecl operator new[](unsigned int)" (??_U@YAPAXI@Z) already defined in msvcprtd.lib(newaop_s.obj) Debug/DuckLib_Debug.dll : fatal error LNK1169: one or more multiply defined symbols found

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!