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

Discussion in 'C Programming' started by PCHOME, Apr 7, 2005.


    PCHOME Guest

    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?

    PCHOME, Apr 7, 2005
    1. Advertisements


    Eric Sosman Guest

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


    .... but I must warn you that you will probably not be
    satisfied with the answer. Life is like that, sometimes.
    Eric Sosman, Apr 7, 2005
    1. Advertisements

  3. If I allocate 1M memorey and forget to free it in my program, I know
    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.
    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.)
    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
    Gordon Burditt, Apr 7, 2005
  4. 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
    Mark McIntyre, Apr 11, 2005
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.