What is a memory leak?

前端 未结 8 2133
无人共我
无人共我 2020-11-27 05:50

Obviously Wikipedia has a fair amount of information on the topic, but I wanted to make sure I understand. And from what I can tell it\'s important to understand the stack/h

8条回答
  •  [愿得一人]
    2020-11-27 06:19

    In garbage-collected systems, the term "memory leak" can sometimes seem a bit nebulous. I would offer the following definition, which is just as applicable to garbage-collected systems as to those which use explicit deallocation: A program or subprogram P has a memory leak if there exists an initial sequence of inputs S and repeating pattern of inputs P, such that:

    1. Feeding the program or subprogram input S followed by P will leave the program in the same "meaningful" state as it had before P, but
    2. For any quantity of memory Q, there exists some number N of repetitions, such that feeding the program input S followed by N repetitions of P will cause the program to use more than quantity Q of memory.

    It is possible for a program without a memory leak to have memory usage which is unbounded with respect to the size of the input, if all of the input is in fact contributing to the program's state. For example, a program to read in an input file and write it out in reverse order will require enough memory to hold the file. On the other hand, a program with a memory leak will require an unbounded amount of memory to handle an infinite input stream, even though the amount of memory required should be finite.

提交回复
热议问题