如果一个数组在循环中重新分配并且从未在Fortran中释放,会发生什么?

Pip*_*ppi 0 fortran

我想知道以下代码对内存的作用:

program A

While (t < large number)
 allocate(a)
 ...

end program
Run Code Online (Sandbox Code Playgroud)

"allocate(a)"是指在每次迭代时引用相同的内存位置,如果在程序结束之前没有使用deallocate(a),是否存在内存泄漏?

M. *_* B. 5

答案是分配已经分配的项是错误的,所以这个代码示例是错误的.

如果项目被声明为,我尝试的编译器会在运行时注意到错误allocatable.他们没有注意到该项是否已使用该pointer属性声明.在这种情况下,您有内存泄漏,因为内存已在早期迭代中保留,但由于指针已被重用,因此无法再到达它.