bash 中的垃圾收集

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14806296/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 04:31:28  来源:igfitidea点击:

Garbage collection in bash

linuxbash

提问by sashang

Does bash run a garbage collector? Can it be controlled via some command line options? I can't find anything on the net about this.

bash 是否运行垃圾收集器?可以通过一些命令行选项来控制吗?我在网上找不到任何关于此的信息。

I have a bash script that runs and over a few days its memory usage increases. I want to know where the memory is going.

我有一个运行的 bash 脚本,几天后它的内存使用量增加了。我想知道记忆的去向。

采纳答案by that other guy

Bash does not run a garbage collector as such. Since it has no concept of references, there is no need to find data without references. It does free memory no longer in use, though.

Bash 本身并没有运行垃圾收集器。由于它没有引用的概念,所以没有引用就不需要查找数据。不过,它确实释放了不再使用的内存。

Here's a simple demonstration of memory usage before and after declaring and overwriting a large variable. Memory usage goes up then down again:

这是声明和覆盖大变量之前和之后的内存使用情况的简单演示。内存使用量上升然后再次下降:

ps -o rss -p $$
var=$(printf "%s\n" {1..100000})
ps -o rss -p $$
var="smallstring"
ps -o rss -p $$