+ Reply to Thread
Results 1 to 2 of 2

Thread: Why does below program crashes in Debug Mode and in Release mode it works fine?

  1. #1

    Why does below program crashes in Debug Mode and in Release mode it works fine?

    Below program crashes in Debug Mode and in Release mode it works fine, why it does so?

    Code:
    class CMeow
    {
    public:
    	CMeow()
    	{
    		OutputDebugString("CMeow::CMeow") ;
    	}
    
    	~CMeow()
    	{
    		OutputDebugString("CMeow::~CMeow") ;
    	}
    } ;
    
    void CreateMeow()
    {
    	CMeow* pMeow = new CMeow[2] ;
    
    	delete pMeow ;
    	pMeow = NULL ;
    }
    Please help.

  2. #2
    It seems that you are using wrong way to delete a array pointer.

    You should use below method to delete pointer to an array.

    Code:
    void CreateMeow()
    {
    	CMeow* pMeow = new CMeow[2] ;
    
    	delete []pMeow ;//note [] here
    	pMeow = NULL ;
    }

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts