answersLogoWhite

0

What is memory leak?

Updated: 8/11/2023
User Avatar

Wiki User

16y ago

Best Answer

When a piece of software running for an extended time uses more and more memory. The software is not releasing its resources correctly! And so the machine cannot recoup memory.

It is possible that eventually the machine will crash, or the offending software will need restarted.

User Avatar

Wiki User

16y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

16y ago

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.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

A memory leak occurs when memory is allocated and neither freed nor accessible

.

For example:

...

int func()

{

char *ptr = malloc(sizeof(char) * 1024); /* Allocate memory */

return 0; /* local var ptr goes out of scope and is no longer accessible */

}

The memory wasn't freed and is no longer accessible.

It's now a block of orphaned memory.

The same happens here:

...

int a = 10;

int *ptr = malloc(sizeof(int) * 1024); /* Allocate memory */

ptr = &a; /* Old pointer value lost and can no longer be free()'d using ptr. */

^ More orphaned memory (Memory leak).

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is memory leak?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is caused when an application does not properly release memory allocated to it that it no longer needs and continually requests more memory than it needs?

memory leak


What happens when class libraries leak memory in c plus plus?

A memory leak is when allocated memory that is no longer needed is not deallocated. Eventually, the memory pool is unable to satisfy an allocation request, and the program fails. A memory leak is a programming bug. When class libraries leak memory, they need to be fixed, just like any other piece of code that has bugs. If they came from a vendor, then that vendor needs to fix them.


What is java memory leak?

That means a memory leak in a program written in Java. A memory leak means that as the program runs, more and more memory is wasted - usually by being assigned and not de-assigned again. In Java this is not as usual as in other languages, since unused memory is normally reclaimed automatically by the garbage collector.


How do you fix a memory leak?

reboot the machine


What is memory leak problemin java?

Memory leaks do not occur in Java as the garbage collector clears the memory which has no references.


What causes a memory leak?

A memory leaks can occur in a computer when a program on one's computer improperly manages the computer's memory allocations. This may happen when a object is stored but cannot be accessed by a running code.


How can delete operator used to prevent memory leak?

ss


If you notice that performance slows after a system has been up and running without a restart for some time would you suspect a memory leak?

True, you can assume that a memory leak is what is causing you problems.


Is caused when an application does not properly release memory allocated to it that it no longer needs and continually requests more memory than it needs?

memory leak


A memory leak is the result of a program allocating memory for use?

It's the result of non-releasing memories when they are not needed anymore.


What is resource leak in java?

when a program consumes memory but is unable to release it back is known as resource leak solution for this is finally keyword by vidhya.t


Can a Java application have memory leak?

Java has a fairly sophisticated garbage collection system, and in general you don't worry about memory leaks, as they only happen in a few very specific circumstances (notably, when adding listeners to Swing GUI objects and not removing them). If you need more sophistcated memory management, java provides the clases in the java.lang.ref package.