One of the most challenging aspects of developing the previous version of ForTrilinos was devising a reference-counting scheme to ensure safe type finalization in Fortran and corresponding object destruction in C++.  It's interesting to see that the SWIG-generated file forepetra.f90 on the new develop branch contains an Epetra_Object derived type with a type(c_ptr) component.  Will that component become associated with the C++ object that the Fortran object shadows?   Given that there's no final subroutine on the type, is there a strategy to avoid memory leaks and dangling pointers?  How will the C++ code get notified when the Fortran object goes out of scope so that C++ knows its safe to destroy the object?  How will the Fortran code get notified if C++ destroys the object?  

What will happen with an expression such as

type(Epetra_Object) :: a,b,c

a = f(b) + g(c)

where f and g are functions that have Epetra_Object results containing c_ptr components that presumably are associated with C++ objects that were instantiated at the direction of Fortran inside each function.  After the above assignment completes, the Fortran code no longer has a name associated with the two function results so the Fortran program has no way to direct C++ to destroy the corresponding C++ objects.

Damian

More Damian W. I. Rouson's questions See All
Similar questions and discussions