定义了个八叉树的数据结构[Fortran] 纯文本查看 复制代码 type facept
integer(4) :: dep !深度
integer(4) :: fac !当前占据点
real(8), dimension(3) :: cx
logical :: leaf,ocp !leaf:是否为叶子(无分支);ocp:是否被占据
type(facept), pointer :: NT0,NT1,NT2,NT3,NT4,NT5,NT6,NT7,NT8
end type facept
[Fortran] 纯文本查看 复制代码 type(facept), pointer :: pp
allocate(pp)
使用过程中指针的八叉树结构分了很多级,现在使用完了想释放掉所有赋给指针的内存
[Fortran] 纯文本查看 复制代码 recursive subroutine release
use octree
implicit none
if(.not. pp%leaf) then
pp=>pp%NT1
call release
deallocate(pp%NT1)
pp=>pp%NT2
call release
deallocate(pp%NT2)
pp=>pp%NT3
call release
deallocate(pp%NT3)
pp=>pp%NT4
call release
deallocate(pp%NT4)
pp=>pp%NT5
call release
deallocate(pp%NT5)
pp=>pp%NT6
call release
deallocate(pp%NT6)
pp=>pp%NT7
call release
deallocate(pp%NT7)
pp=>pp%NT8
call release
deallocate(pp%NT8)
end if
pp=>pp%NT0
end subroutine
这样从进程管理器中可以看出明显内存减小了很多,也就是释放掉了内存,但是感觉效率有点低,尤其是数据量大的时候释放的很慢,感觉到可能哪里不太合理,于是又写个个:
[Fortran] 纯文本查看 复制代码 recursive subroutine release(tp)
use octree
implicit none
type(facept), pointer :: tp
if(.not. tp%leaf) then
call release(tp%NT1)
call release(tp%NT2)
call release(tp%NT3)
call release(tp%NT4)
call release(tp%NT5)
call release(tp%NT6)
call release(tp%NT7)
call release(tp%NT8)
else
deallocate(tp)
end if
end subroutine
这样改完之后编译运行都没有问题,但是并没有释放掉内存,大家帮忙看下怎么回事,如何高效的释放掉内存,谢谢!!
|