Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6919765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:02:25+00:00 2026-05-27T10:02:25+00:00

I am a C++ programmer on the Windows platform. I am using Visual Studio

  • 0

I am a C++ programmer on the Windows platform. I am using Visual Studio 2008.

I usually end up in the code with memory leaks.

Normally I find the memory leak by inspecting the code, but it is cumbersome and is not always a good approach.

Since I can’t afford a paid memory leak detection tool, I wanted you guys to suggest the best possible ways to avoid memory leaks.

  1. I want to the know how the programmer can find memory leaks.
  2. Is there any standard or procedure one should follow to ensure there is no memory leak in the program?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:02:26+00:00Added an answer on May 27, 2026 at 10:02 am

    Instructions

    Things You’ll Need

    • Proficiency in C++
    • C++ compiler
    • Debugger and other investigative software tools

    1

    Understand the operator basics. The C++ operator new allocates heap memory. The delete operator frees heap memory. For every new, you should use a delete so that you free the same memory you allocated:

    char* str = new char [30]; // Allocate 30 bytes to house a string.
    
    delete [] str; // Clear those 30 bytes and make str point nowhere.
    

    2

    Reallocate memory only if you’ve deleted. In the code below, str acquires a new address with the second allocation. The first address is lost irretrievably, and so are the 30 bytes that it pointed to. Now they’re impossible to free, and you have a memory leak:

    char* str = new char [30]; // Give str a memory address.
    
    // delete [] str; // Remove the first comment marking in this line to correct.
    
    str = new char [60]; /* Give str another memory address with
                                                        the first one gone forever.*/
    
    delete [] str; // This deletes the 60 bytes, not just the first 30.
    

    3

    Watch those pointer assignments. Every dynamic variable (allocated memory on the heap) needs to be associated with a pointer. When a dynamic variable becomes disassociated from its pointer(s), it becomes impossible to erase. Again, this results in a memory leak:

    char* str1 = new char [30];
    
    char* str2 = new char [40];
    
    strcpy(str1, "Memory leak");
    
    str2 = str1; // Bad! Now the 40 bytes are impossible to free.
    
    delete [] str2; // This deletes the 30 bytes.
    
    delete [] str1; // Possible access violation. What a disaster!
    

    4

    Be careful with local pointers. A pointer you declare in a function is allocated on the stack, but the dynamic variable it points to is allocated on the heap. If you don’t delete it, it will persist after the program exits from the function:

    void Leak(int x){
    
    char* p = new char [x];
    
    // delete [] p; // Remove the first comment marking to correct.
    
    }
    

    5

    Pay attention to the square braces after “delete.” Use delete by itself to free a single object. Use delete [] with square brackets to free a heap array. Don’t do something like this:

    char* one = new char;
    
    delete [] one; // Wrong
    
    char* many = new char [30];
    
    delete many; // Wrong!
    

    6

    If the leak yet allowed – I’m usually seeking it with deleaker (check it here: http://deleaker.com).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a long-time C++ programmer developing on Windows, and have been using Visual Studio
As a C++ programmer I sometimes need deal with memory buffers using techniques from
On Windows/Linux platform,I as a common computer user,could not nearly find any software written
I am an experienced C++, C# programmer on Windows platform and would like to
I'm a starter C and C# programmer, mainly developing for the Windows platform (XP
I'm interested in learning how to program using Microsoft's Visual C++ for Windows. In
I'm a new Windows programmer and I'm not sure where I should store user
As I was a Windows programmer it was so easy to show a message
How long does it take for an experienced Windows programmer to learn writing simple
For my side job as programmer, I need Windows. It will be installed in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.