What happens if I do not free memory....

P

PCHOME

Hi!
It it about C.

If I allocate 1M memorey and forget to free it in my program, I know
that part of memory will be unable for using later in my program.

1)Will the OS collect it for later use while my program terminates?

2)Or it will become unavailable even my program terminates?
If 2) is true, When will that 1M becomes available? After I reboot
my machine?

Thanks!
 
E

Eric Sosman

PCHOME said:
Hi!
It it about C.

If I allocate 1M memorey and forget to free it in my program, I know
that part of memory will be unable for using later in my program.

1)Will the OS collect it for later use while my program terminates?

2)Or it will become unavailable even my program terminates?
If 2) is true, When will that 1M becomes available? After I reboot
my machine?

This is Question 7.24 in the comp.lang.c Frequently
Asked Questions (FAQ) list

http://www.eskimo.com/~scs/C-faq/top.html

.... but I must warn you that you will probably not be
satisfied with the answer. Life is like that, sometimes.
 
G

Gordon Burditt

If I allocate 1M memorey and forget to free it in my program, I know
that part of memory will be unable for using later in my program.

After you are 7 days overdue in returning it, Blockbuster will
bill you for the retail price for the memory. In Texas, they got
sued for not explaining this policy clearly in their advertising.
1)Will the OS collect it for later use while my program terminates?

Maybe. It depends on the OS. If an OS allows you to ABORT a program
with a keystroke or command, chances are it will recover the memory
in that situation (when the program has no chance to free the memory),
and it will also be able to recover it on normal termination.

There are a few OSs that won't. Modern general-purpose OSs will:
UNIX, Linux, Windows. I'm not so sure about early versions of
MS-DOS. Embedded processors may not really have anything like
program "normal termination": it's running all the time.

Incidentally, that the OS can recover memory allocated by malloc()
does not necessarily imply that it can recover memory allocated
by other, more system-specific means (shared memory, font handles,
window handles, Terminate And Stay Resident, etc.)
2)Or it will become unavailable even my program terminates?
Possibly.

If 2) is true, When will that 1M becomes available? After I reboot
my machine?

It may not be possible to reboot your machine (where's the reboot button
on a digital watch? How about a cell phone?)

Gordon L. Burditt
 
M

Mark McIntyre

On 7 Apr 2005 14:01:15 -0700, in comp.lang.c , "PCHOME"

(snip question about whether memory is freed on programme termination)

This is a FAQ - 7.24
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top