You are not logged in. Please login at www.codechef.com to post your questions!

×

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

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

imcode's gravatar image

0★imcode
49203136
accept rate: 0%

edited 18 Jun '13, 22:08

vinayak%20garg's gravatar image

4★vinayak garg
3.7k113249


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

link

answered 18 Jun '13, 22:00

kuruma's gravatar image

3★kuruma
17.7k72143209
accept rate: 8%

Don't worry. The memory will be freed after your program has finished its execution.

link

answered 18 Jun '13, 21:53

timepass123's gravatar image

2★timepass123
21139
accept rate: 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.

link

answered 18 Jun '13, 21:54

bhambya's gravatar image

2★bhambya
31025
accept rate: 16%

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.

link

answered 18 Jun '13, 22:03

vinayak%20garg's gravatar image

4★vinayak garg
3.7k113249
accept rate: 18%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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