什么样的问题会导致缺乏解除分配? [英] what kind of problems can lack of deallocation cause?

查看:182
本文介绍了什么样的问题会导致缺乏解除分配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前遇到了一个问题,我得到了



***检测到了glibc *** ./efit:free():invalid下一个大小(快):0x00000000006127f0 ***



与通常的内存映射和回溯信息一起提供 glibc 错误。然而,我无法找到这个问题的原因。这似乎(基本上)我的整个程序是在这种情况发生的时候完成的。我在网上阅读的一件事是,这可能是由于缺乏解除分配。

现在,我一直在运行该程序,但没有释放一些我的数组(我在这种印象可能导致内存泄漏,但这只会影响程序运行时的性能和效率)。现在,当我开始新程序时,我遇到了这个错误。



有可能我之前执行的程序没有取消分配我的数组是'回到困扰我'的意义在于,前面的执行过程中存在不自然的记忆,我试图写信给它?



如果不是,我完全被这个错误所困惑。任何线索,我应该开始看什么和/或我应该如何调试才能找到它?



值得一提的是,我正在使用gfortran编译

>

编辑:
,而编译选项一开始并没有直接识别这个问题,它帮助我缩小了它。我在中使用 iat 作为 iat = 1,natoms 的整数变量 loop,然后几行后,认为 iat 1范围内描述了一个不同的整数,natoms 。我正在引用数组边界外的数组。当我更正了编译选项列出的一些警告时,这个错误变成了对错误的更清晰的描述: Fortran运行时错误:数组''的维1的索引'7'isnormed'高于上约束6



这是什么让第一次产生这个错误? (fout,'(a)'),line100'改为 read(fout,'(a)),这是我编写警告告诉我的唯一更改。 ')line100'(去掉逗号)并改变旧的风格角色描述 character * 100 line100 更新字符(100)line100 说明。

解决方案

上次运行程序时发生的错误不会影响下次运行。操作系统加载可执行文件的新版本并为其提供内存。只有当程序将信息写入文件并在下次运行时读取它们,才可以传输信息。



当操作系统自动释放内存时程序结束。此外,对于Fortran> = 95,程序本地的可分配数组在程序返回时会自动由Fortran分配。



很可能您有一个内存使用问题正在破坏描述程序使用的内存的内部结构。通过使用Fortran,可以通过调用者和被调用者之间的参数不匹配,通过对数组末尾或指针进行索引来实现。你在使用指针吗?如果不是这样,在这个时代,前两个通常很容易防范。将你的程序放入模块中并使用这些模块。这将允许编译器检查参数一致性。编译运行时检查下标的选项。这将发现是否索引超过数组的末尾并存储在其他内存中。

使用gfortran,请尝试以下编译器选项:-O2 -fimplicit-none -Wall -Wline-truncation -Wcharacter-truncation -Wsprising -Waliasing -Wimplicit-interface -Wunused-parameter -fwhole-file -fcheck = all -std = f2008 -pedantic -fbacktrace。如果其中的一些发现了太多的警告,那么这个问题的重要一点是fcheck = all,或者甚至更窄,fcheck = bounds。

i am currently experiencing a problem were i get

*** glibc detected *** ./efit: free(): invalid next size (fast): 0x00000000006127f0 ***

with the usual memory map and backtrace information that comes with a glibc error. i am, however, unable to find the cause of this problem. it seems like (basically) my entire program is finished by the time this happens. one thing i read online is that this could be due to lack of deallocation.

now, i have been running the program without deallocating a few of my arrays (i was under the impression that deallocation can cause memory leaks but that this will only affect the performance and efficiency of the program while it runs). now, when i start the program fresh, i am running into this error.

is it possible that my previous executions of the program without deallocating my arrays is 'coming back to haunt me' in the sense that there is unfree memory from previous executions which i am trying to write to?

if not i am completely confused by this error. any clues on where i should begin to look and/or how i should debug to find it?

for what it is worth, i am using gfortran to compile

EDIT: while the compilation options did not directly identify this problem at first, it helped me to whittle it away. i was using an integer variable iat for iat=1,natoms in a do loop, and then a few lines later, thought iat was describing a different integer within the bounds of 1,natoms. i was referencing an array outside the bounds of the array. when i corrected a few of the warnings listed by your compilation options, this error turned into a much clearer description of the error: Fortran runtime error: Index '7' of dimension 1 of array 'isnormed' above upper bound of 6.

What was it that kept this error from being produced the first time? the only reach changes i made which the compilation warnings told me about were changing read(fout, '(a)'), line100' toread(fout, '(a)') line100' (removing the comma) and changing old style character descriptions character*100 line100 to newer character(100) line100 descriptions.

解决方案

An error from a previous run of your program cannot effect the next run. The OS loads a new version of the executable and provides it with memory. Only if you have the program write out info to a file and read it in on the next run can their be transfer of information.

Memory is automatically deallocated by the OS when the program finishes. Additionally, for Fortran >=95, allocatable arrays that are local to a procedure are automatically deallocated by Fortran when the procedure returns.

Most likely you have a memory usage problem that is corrupting the internal structures that describe memory that is used by your program. With Fortran this is possible by having argument mismatched between caller and callee, by indexing past the end of an array, or with pointers. Are you using pointers? If not, the first two are typically easy to guard against in this era. Place your procedures into modules and "use" those modules. This will allow the compiler to check argument consistency. Compile with the option for run-time checking of subscripts. This will find out if you are indexing past the end of an array and storing in other memory.

With gfortran, try the following compiler options: -O2 -fimplicit-none -Wall -Wline-truncation -Wcharacter-truncation -Wsurprising -Waliasing -Wimplicit-interface -Wunused-parameter -fwhole-file -fcheck=all -std=f2008 -pedantic -fbacktrace. If some of these identify too many warnings, the important one for this issue is fcheck=all, or even narrower, fcheck=bounds.

这篇关于什么样的问题会导致缺乏解除分配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆