×

# Have I lost memory on my hard disk due to memory leakage?

 1 Until now I have always forgotten to free() the ptrs after use. I came to know now that this leads to memory leaks. Have I lost some bit of memory on my hard disk? How do I "free" it? asked 18 Jun '13, 21:39 0★imcode 49●20●31●36 accept rate: 0% 3.7k●11●32●49

 2 Hello, It seems you are confusing RAM memory with ROM memory and it also seems you are thinking on a memory leak as something catastrophic!! First of all, critical system information like boot-records and possibly some controllers drivers are stored in what it's known as ROM memory. ROM stands for Read-Only Memory, which is a non-volatile memory and it's in a sense, persistent. That's why after you turn your computer off and on several times you can still access Firefox, Word, Excel, Media Player, and all other programs which are, in a sense, permanently stored on disk. When you execute a program however, you are accessing what is known as RAM memory, which stands for Random Access Memory. Unlike the previous memory, RAM memory is volatile, which means that it is wiped out after you turn off your computer or after you stop the execution of any process that is using it. That's typically the reason why Hard Disks can go up to Terabytes in capacity (as they might be used to store many permanent information), while RAM memories are typically of the order of 2-4 Gigabytes (some thousands times smaller). Hence, when you start a program, after you've compiled it, it is totally executed over RAM memory. On this sense, a memory leak is simply memory that contains garbage, or memory that was allocated but not actually used. This typically arises when working with pointers maybe because a pointer in C IS a memory adress, that is, it serves as a variable which stores the adress of a specific RAM location, and it's easy to mess things up and get memory leaks unless memory is well managed. A good tool that it's usually mentioned to see this is valgrind which checks for memory leaks under Linux. Note however, that, after you stop executing your program and shut down your pc, all memory is cleared, so, you have nothing to worry about. Also, thanks for the question, this is definitely NOT an easy subject!! Best regards, Bruno answered 18 Jun '13, 22:00 3★kuruma 17.7k●72●143●209 accept rate: 8%
 0 Don't worry. The memory will be freed after your program has finished its execution. answered 18 Jun '13, 21:53 21●1●3●9 accept rate: 0%
 0 The memory that you did not free was allocated in RAM not hard disk. It is freed automatically. To free hard disk space (if any) run check disk utility. Also don't ask such questions here. Redirect such questions to appropriate forums. answered 18 Jun '13, 21:54 2★bhambya 310●2●5 accept rate: 16%
 0 The memory is allocated in main memory and not on hard disk. So you haven't lost anything on hard disk. Also OS reclaims all the memory from process, including the leaked memory once a process terminates. In small programs memory leakage is unlikely to cause trouble (goes un-noticed). But as a good programming practice always remember to free() the allocated memory. Or even better use C++ containers (no need to manage memory) or Smart pointers. answered 18 Jun '13, 22:03 3.7k●11●32●49 accept rate: 18%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×1,477
×62

question asked: 18 Jun '13, 21:39

question was seen: 1,643 times

last updated: 18 Jun '13, 22:08