悲催的科学匠人 - 冷水's blog
fortran 2003 析构函数调用条件
真他妈的晕
function getptr(...) type(XXX),pointer,dimension(:) :: getptr call fetchptr(... getptr) end function ... mydata => getptr(..) ...
事实证明getptr指向的XXX类型对象会在getptr函数返回前被finalize。如果采用subroutine形式实现getptr就不会。
真是坑爹啊
When finalization occurs
1 Finalization occurs for the target of a pointer when the pointer is deallocated. If an object is allocated through pointer allocation and later becomes unreachable because all pointers to that object have had their pointer association status changed, finalization on the object does not occur.
指针被释放时,指向目标的final过程被调用。如果被动态开辟的对象失去所有指针引用,则final过程无法被调用。
2 Finalization of an allocatable entity occurs with the entity is deallocated.
allocatable的对象被释放时,对象的final过程被调用。
3 Finalization for a nonpointer, nonallocatable object that is not a dummy argument or function result occurs immediately, before the object is undefined by the execution of a RETURN or END statement. If the object is defined in a module and no active procedures are still referencing the module, finalization does not take place.
非指针,非allocatable,不是哑元,不是返回值,这样的对象在所在域的RETURN or END时会被自动fanalize。module中的鼓励对象,无法finalize。
4 Finalization of a structure constructor referenced by an executable construct occurs after execution of the innermost executable construct containing the reference.
5 Finalization for a function referenced by an executable construct takes place after execution of the innermost executable construct containing the reference.
6 Finalization for the result of a function referenced by a specification expression in a scoping unit takes place before the first statement in the scoping unit executes.
7 Finalization of a nonpointer, nonallocatable object that is an actual argument associated with an INTENT(OUT) dummy argument occurs when a procedure using the argument is invoked.
8 Finalization of a variable in an intrinsic assignment statement takes place after evaluation of the expression and before the definition of the variable.
Non-finalized entities
If program execution is terminated, either by an error, such as an allocation failure, or by the execution of a STOP or END PROGRAM statement, entities existing immediately prior to termination are not finalized.
主程序结束前,还未释放的对象无法自动finalize
A nonpointer, nonallocatable object that has the SAVE attribute or that you specify in the main program is never finalized as a direct consequence of the execution of a RETURN or END statement