1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

memory lead

Discussion in 'C' started by buddy, Sep 10, 2007.

  1. buddy

    buddy New Member

    Joined:
    Aug 31, 2007
    Messages:
    22
    Likes Received:
    0
    Trophy Points:
    0
    what is mean by memory leak in c programming ?? can anyone explain with an example??plz.
     
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    If you allocate memory dynamically from the heap, then don't return it before the program exits, it's no longer available for other programs.
     
  3. listendinesh

    listendinesh New Member

    Joined:
    Aug 3, 2007
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    0
    Here is the example

    Code:
    int main()
    {
    char *buffer1;
    char *buffer2;
    buffer1 = (char *)malloc(5*sizeof(char));
    buffer2 = (char *)malloc(5*sizeof(char));
    buffer1 = buffer2; // This will lead Memory leak
    .
    .
    .
    .
    }
     

Share This Page