Top VPS Hosting Provider

Welcome to the myhosting.com Forums.
+ Reply to Thread
Results 1 to 2 of 2

Thread: leaks

  1. #1
    Rusher is offline Master Member
    Join Date
    May 2010
    Posts
    544

    Default leaks

    Any general tips for reducing memory leaks when you're putting together a basic computer program?

  2. #2
    suwunk is offline Super Moderator
    Join Date
    Aug 2010
    Posts
    1,082

    Default

    A memory leak occurs when memory is allocated (for example using a malloc() function), and not released. Often the error is caused by allocating the memory then returning from a function before de-allocating it.

    To avoid the problem requres two steps:

    Obviously, be careful writing code so that whenever memory is allocated, its always deallocated properly.

    Add code so that the amount of free memory is visible; that way you can detect memory leaks - although not necessarily who's doing it.

    As a part of the second step, it may be useful to have your own versions of malloc(), realloc() and free() which keep track of which functions call them. That can make it easier to find out who "owns" the lost memory.

    One nasty problem is the operating system leaking memory. This is much harder to detect, apart from the application gradually slowing down as the dynamic memory has to start using hard drive as memory.

    Read more: Answers.com - What is a memory leak and how can you avoid it


 

Similar Threads

  1. data leaks
    By WrigleyF in forum Virtual Server
    Replies: 0
    Last Post: 2011-01-19, 08:42 AM
  2. future of leaks
    By WrigleyF in forum News, Announcements, and Notices
    Replies: 0
    Last Post: 2010-08-06, 12:01 PM

Posting Permissions

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