memory - htop 显示内存仍在使用,即使调用了 deallocate
问题描述
mac osx (catalina)
gfortran 9.3.0 from homebrew
htop 2.2.0 from homebrew
我有以下程序memtest.f90
,我在其中编译gfortran memtest.f90 -o test
然后调用./test
program main
implicit none
integer, parameter :: n=100000000
real, allocatable :: values(:)
print *, "no memory used yet, press enter"
read(*,*)
allocate(values(n))
values = 0.0
print *, "used a lot of memory, press enter"
read(*,*)
deallocate(values)
print *, "why is the memory still there in htop"
read(*,*)
end program main
我预计程序使用的内存在调用 deallocate 语句后会下降,但是,正如它所表明的那样,htop
它继续徘徊在大约 382 MB(见下图)
这是内存泄漏吗?如果是,我该如何正确释放内存,或者我只是在查看程序消耗的内存时做错了什么?
解决方案
该程序通常不会将内存返回到低于某个阈值的操作系统。也可能需要一些时间才能被释放。这不是 Fortran 问题,而是系统问题。
我没有将它标记为这个的副本malloc 实现会将释放的内存返回给系统吗?因为它是相当间接的,值得一些评论,但问题就在那里。Fortran 编译器通常调用malloc
操作系统提供的或随附的 C 编译器的 C 库。
推荐阅读
- python - 无法检查 QAction
- r - R - For 循环针对数据框列表运行代码
- javascript - 使用 Mapbox GL JS 单击关闭标记层时如何关闭弹出窗口
- python - 显示奇怪行为的 RandomForestClassifier 的随机超参数搜索
- javascript - Javascript var 返回“未定义”
- php - 如何使用 php 从文本文件中显示定义列表
- javascript - 如何从重组转换为钩子?
- c# - Unity 中的全局变量(在所有场景中更改字体大小、颜色)
- pandas - 如何使用嵌套类别在散景中绘制堆叠的 vbar
- android - 错误消息:确保首先调用 FirebaseApp.initializeApp(Context)