Question:
Explain the term memory leak and describe what you can do if one occurs on your PC?
Angel
2010-09-26 17:49:44 UTC
i know what memory leak is the allocating and deallocating , but i can not find anywhere on how to solve or maintain it to aminmum other then dl this program to check for that errors and bugs so i guess i need to know what is the solution for a memory leak
Three answers:
Shadow Wolf
2010-09-26 18:28:59 UTC
A memory leak is allocating memory from the heap and then forgetting to de-allocate it. In a C program, that would mean using malloc() or a related function and then forgetting to return the memory to the heap with a call to free() when you are done with it. Each time your program hits the part where memory is allocated, the memory used will grow. Eventually all resources will get used up and the program and/or computer may crash.



If it isn't one of your programs, then a memory manager may help but it may not actually be needed. WinXP or later will usually return the memory back to the pool when the program crashes or closes. This isn't the best solution but it might help you deal with it. Complaints to the software vendor may get you more reliable results if you can reproduce the problem on any computer. What appears to be a memory leak may only be a symptom of another problem.



If it is your own program, then you need to find the memory leak. This is the most reliable method of fixing a memory leak. Every time you allocate memory you have to return it. So, using C for an example, for every malloc() you have to have a free() that matches it. If you aren't using C, then you should have matching allocate and deallocate functions. Also be careful that you don't go out of scope before deallocating the memory as this could cause a leak as well.



There are other problems that look like memory leaks. If your computer crashes after an hour of running or some other fixed time period, then you probably have a memory leak or something that is using up memory similar to a memory leak. Shutting down or closing programs may eventually lead you to the cause. I know I had one instance where a normally good program was causing a crash and a low memory warning. After about 1 hour, the computer would lock up. It ended up being a log file was getting overloaded because of a bit of malware that was undetected by my anti-virus program. It technically wasn't a memory leak, but it did eventually use up all memory and crash the computer.



Shadow Wolf
Gardner
2010-09-26 17:55:16 UTC
If it's not your program or one you have access to the source code for then the best solution for memory leaks is usually a good memory manager program.
gilmour
2017-01-11 14:03:57 UTC
Terminal velocity. you may think of of it as brought about via the collisions between the falling merchandise and the billions and billions of molecules interior the ambience. each collision has a tendency to sluggish the falling merchandise a tiny bit. the quicker the object is going down or the greater advantageous it quite is floor section the greater collisions it has in line with 2nd. at last there is numerous collisions in line with 2nd that the falling merchandise can not pass any quicker.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...