#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    13
    Rep Power
    0

    How can I prevent memory leaks


    Hey, guys! I was looking for a memory leak in my program for two weeks. :brrr: Please tell me, is there any way to protect from leaks, how can I prevent leaks? Is there any way? :confused: Any ideas will be grateful!
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,392
    Rep Power
    1871
    Aren't you forgetting something

    Comments on this post

    • admiraln agrees : Yes, but it leaked out of his mind.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,110
    Rep Power
    1803
    Mostly it is about coding standards and design. When you code something that allocates memory, code the release at the same time.

    In C++ keeping memory allocation and release in matching constructors/destructors can help, but also the use of smart pointers

    In Visual C++ if your code terminates with unreleased memory, the debugger output window will tell you that. In Linux Valgrind can help track memory leaks.

    Another solution is to use a language where the problem just does not arise such as C# or Java or by using gcnew in C++/CLI

    Comments on this post

    • Gucho agrees
    Last edited by clifford; February 7th, 2013 at 08:24 AM.
  6. #4
  7. No Profile Picture
    Still Learning
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Location
    Montreal, Canada
    Posts
    55
    Rep Power
    39
    Without code you have to go back to pointer and memory school.

    http://www.ibm.com/developerworks/aix/library/au-toughgame/
    http://mousomer.wordpress.com/2010/11/03/simple-rules-to-avoid-memory-leaks-in-c/

    Look for "memory leaks in c" in google and you will find more like these.
    Last edited by admiraln; February 7th, 2013 at 09:15 AM.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    13
    Rep Power
    0
    Yes, I know that Java does not have problems with memory leaks
    Thanks for the links
  10. #6
  11. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,549
    Rep Power
    2337
    Ignore, he's a spammer.
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    13
    Rep Power
    0
    Originally Posted by ptr2void
    Ignore, he's a spammer.
    Yeah, He is devil's spammer :thumbs:

    Comments on this post

    • Gucho agrees

IMN logo majestic logo threadwatch logo seochat tools logo