Search code examples
memorydiskhard-drive

How is disk memory being used/consumed by programs?


A dummy question: Recently my disk ran out of memory: I kept getting java.OutOfMemoryError, java heap space, later my Virtual Box encountered "Not Enough Free Space available on disk" error. Then it turned out that my 256GB SSD had been almost all consumed/used.

So I was wondering how running the programs could consume my memory/disk usage? How does this work? I know the basics behind this, allocating space on a heap/stack, then deallocating them after use. (Correct me if I'm wrong.) But if this is the case, then the disk should not be used up, right? (if I don't add anything else onto my desktop, only using it to run a definite number of programs)

I really wanted to understand how the disk/memory is being consumed/used by running programs. If this question has been asked before, please relate it to that one. I apologize for dummy question, but I believe it will be helpful to fellow programmers like me.

Thanks for making it clearer. Q1: Why do programs consume disk space? A2: How does "java.OutOfMemoryError, java heap space" occur? related to memory, is it?


Solution

  • Why do programs consume disk space?

    I know the basics behind this, allocating space on a heap/stack, then deallocating them after use. But if this is the case, then the disk should not be used up, right?

    In fact, it can be used up.
    Memory allocations can consume hard-disk space if the allocation in your process's virtual memory happens to be mapped to a pagefile on disk, and your pagefile size is set to be managed by the operating system.

    If you want to know more about memory mapping there's a great question here: Understanding Virtual Address, Virtual Memory and Paging

    The page-file grow won't actually be a direct response to your allocation, more a response to the new current commit size being close to the reserved size. If you want to know more about this process (commit vs reserved, stack expansions, etc) I recommend reading Pushing the Limits of Windows: Physical Memory.

    Why does java.OutOfMemoryError occur?

    http://docs.oracle.com/javase/7/docs/api/java/lang/OutOfMemoryError.html

    Thrown when the Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector.

    Generally this happens because your pagefile is too small or your disk is too full.

    See also: