Science Fair Projects Ideas - Memory leak

All Science Fair Projects

      

Science Fair Project Encyclopedia for Schools!

  Search    Browse    Forum  Coach    Links    Editor    Help    Tell-a-Friend    Encyclopedia    Dictionary     

Science Fair Project Encyclopedia

For information on any area of science that interests you,
enter a keyword (eg. scientific method, molecule, cloud, carbohydrate etc.).
Or else, you can start by choosing any of the categories below.

Memory leak

Memory leaks are often thought of as failures to release unused memory by a computer program. Strictly speaking, that behaviour is just more memory consumption. A memory leak occurs when the program loses even the ability to free the memory. Either behaviour diminishes the performance of the computer, as it becomes unable to use all its available memory.

Memory leaks are a rather common error in programming, especially when programming in languages that have no automatic embedded garbage collection (GC), like C and C++, which deeply rely on pointer operations. This has led to the development of a number of tools to detect and prevent this problem from happening. Purify, Valgrind, Insure++ and memwatch are some of the most popular tools for discovering memory leaks in C and C++ programs. It should be noted that GC for C and C++ programs can be included as facilities and are not inherently lacking; GC facilities, if included programmatically, can be used like any other programmatic feature, as Bjarne Stroustrup (the inventor of C++) points out about C++. However GC will not account for all of the programming errors that cause memory leaks.

The main issue is that it is normally a component of the operating system which is responsible for managing memory, and so the result of a memory leak is usually an ever growing amount of memory being used by the system as a whole, not merely by the erroneous process/program. Eventually, all (or too much) of the available memory may be allocated (and not freed) and the entire system (or critical subsystems) can stop working correctly.

In languages providing automatic memory management, like Java, C# or LISP there can be memory leaks too. The memory management does not free an object that is strongly reachable. This is the case if still one or more (also strongly reachable) references exist for the object. (For example, storing an object in a Vector object in Java and later losing/forgetting about the index). The developer is responsible for cleaning up references after use. Nevertheless, automatic memory management is more convenient for developers, as they don't need to implement freeing routines or worry about the sequence in which cleanup is performed. Automatic memory management does impose a small performance overhead with all the extra checking.

Simple example in C

Here is a program that deliberately leaks memory.

int
main(void)
{
   char *string1 = malloc(sizeof(char)*50);
   char *string2 = malloc(sizeof(char)*50);
   scanf("%s", string2);
   string1 = string2; // here the memory created above for string1 is lost "leaked"
                      // it is not pointed to by anything anymore, 
                      // so it cannot be explicitly freed

   free(string2); //this will be successful
   free(string1); //this will be erroneous - attempt to free already freed memory
   return 0;

}

See also

External links

09-23-2007 01:00:40
The contents of this article is licensed from www.wikipedia.org under the GNU Free Documentation License. Click here to see the transparent copy and copyright details
Science kits, science lessons, science toys, maths toys, hobby kits, science games and books - these are some of many products that can help give your kid an edge in their science fair projects, and develop a tremendous interest in the study of science. When shopping for a science kit or other supplies, make sure that you carefully review the features and quality of the products. Compare prices by going to several online stores. Read product reviews online or refer to magazines.

Start by looking for your science kit review or science toy review. Compare prices but remember, Price $ is not everything. Quality does matter.
Science Fair Coach
What do science fair judges look out for?
ScienceHound
Science Fair Projects for students of all ages
All Science Fair Projects.com Site
All Science Fair Projects Homepage
Search | Browse | Links | From-our-Editor | Books | Help | Contact | Privacy | Disclaimer | Copyright Notice