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

Memory Leak detection Program without using any tools

Discussion in 'C' started by asadullah.ansari, Mar 4, 2008.

  1. rahul.mca2001

    rahul.mca2001 New Member

    Joined:
    Feb 13, 2008
    Messages:
    103
    Likes Received:
    0
    Trophy Points:
    0
    i tried and it really works well
     
  2. bashamsc

    bashamsc New Member

    Joined:
    May 22, 2007
    Messages:
    51
    Likes Received:
    7
    Trophy Points:
    0
    Location:
    chennai
    Nice program to detect memory leak. But i want to know how to recover the memory after memory leak and how to prevent it.
     
  3. asadullah.ansari

    asadullah.ansari TechCake

    Joined:
    Jan 9, 2008
    Messages:
    356
    Likes Received:
    14
    Trophy Points:
    0
    Occupation:
    Developer
    Location:
    NOIDA
    This program will tell you
    1. line number
    2. source file name
    3. starting address
    4. total bytes .
    If this is your program then go to that line and call free function for that pointer which is pointing to memory and not deallocated.

    If that is not your program means it may be in binary then You have four information by running this program , then take a pointer which will point to constant address as above 3.
    and set the offset as required based on as above 4 info. then call free function for this pointer.
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    bubyfound, Make sure we discuss only in English.
     
  5. debleena_doll2002

    debleena_doll2002 New Member

    Joined:
    Feb 5, 2008
    Messages:
    119
    Likes Received:
    0
    Trophy Points:
    0
    I am unable to get yout statement. shabbir, Please Can you use QUOTE so that we can easily identify.
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    bubyfound, had one post in non-English and so its directed to him. I have not quoted his non-english posts
     
  7. rashida.par

    rashida.par New Member

    Joined:
    Feb 14, 2008
    Messages:
    21
    Likes Received:
    1
    Trophy Points:
    0
    very nice article
     
  8. donakalz

    donakalz New Member

    Joined:
    Mar 21, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Thanks man for the very very nice code.

    However, I am trying to create a version which works for C++ operators new and delete like this:

    #define new (elemSize) MyNew (elemSize, __FILE__, __LINE__)
    #define new [](elemSize) MyNewArray (elemSize, __FILE__, __LINE__)
    #define delete(memPointer) MyDelete (memPointer)
    #define delete [](memPointer) MyDeleteArray (memPointer)

    and I get the following compiler errors:
    24:1 [Warning] "new" redefined
    26:1 [Warning] "delete" redefined


    Can you think of a workaround for this? Thanks.

    Don
     
  9. donakalz

    donakalz New Member

    Joined:
    Mar 21, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Wow. So quiet in here. Hello? Anybody here?
     
  10. lead.smart34

    lead.smart34 New Member

    Joined:
    Feb 14, 2008
    Messages:
    77
    Likes Received:
    0
    Trophy Points:
    0
    really a very nice code
     
  11. sareen

    sareen New Member

    Joined:
    Feb 26, 2008
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
  12. sareen

    sareen New Member

    Joined:
    Feb 26, 2008
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    sir very easy program
     
  13. asadullah.ansari

    asadullah.ansari TechCake

    Joined:
    Jan 9, 2008
    Messages:
    356
    Likes Received:
    14
    Trophy Points:
    0
    Occupation:
    Developer
    Location:
    NOIDA
    How it will happen? Are You sure about this warning? Because I am using Flexlint tools for making zero warning also.
    By any way can you give at which plateform and compiler you are using ?
     
  14. donakalz

    donakalz New Member

    Joined:
    Mar 21, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    I use windows xp and a DevC++ compiler. I get the error that new and delete are redefined. I also get the error with Netbeans 6.1 for C++. Maybe you could post some code of yours to show how you accomplished this task. Thanks.

    don
     
  15. asadullah.ansari

    asadullah.ansari TechCake

    Joined:
    Jan 9, 2008
    Messages:
    356
    Likes Received:
    14
    Trophy Points:
    0
    Occupation:
    Developer
    Location:
    NOIDA
    I dont know how you are using. Have you some sense. Any compiler is not mad like you. How it will give redefined. I have define as macro. Do you have some skill. If you have some little bit skill then it will run.
     
  16. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
  17. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
  18. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
  19. saroj.pandarkl

    saroj.pandarkl New Member

    Joined:
    Jun 20, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi
    Aa I saw through this forum many people are asking basic question what is memory leak and they are advised to go through google.Can any do a little favour like when creating any variable or ointer things in which area of memory it stores(i mean to say like code segment ,data seg etc).Explanation (undestanding)required on it before going about memory leak
     
  20. inkuar.ikkr

    inkuar.ikkr New Member

    Joined:
    Jun 24, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hello asadullah,

    Could you please send the findleak program for C++ for New, Delete .. methods?

    Thanks,
    INDRA
     

Share This Page