RadialSolver solution gives unallocated memory for Love number results #59
Labels
bug
Something isn't working
Cython
Issue requires experience with Cython and some C
Docs
Documentation and/or Doc Strings needed
RadialSolver
Users have reported that successful runs of
RadialSolver.radial_solver
give unallocated values when accessing the solutions.k, .h, .l etc.This has occurred with, at least, TidalPy v0.5.4 but as discussed below, it is not a TidalPy problem per-say.
The problem is that the
RadialSolverSolution
class performs a heap allocation to memory in order to store the Love number results. It is responsible for freeing this memory when the class instance is destroyed. This particular problem comes up when the solution is destroyed too early.To Reproduce
The common situation where this problem arises is when an outer python function calls radial solver and gets a solution but does not return the solution. This can be reproduced with pure Cython and no use of TidalPy:
To reproduce make a cython class and functions like...
Call this function from another python wrapping function...
You will see unallocated values are printed.
Workaround
We can get the correct values by grabbing a specific value of the array, or by making a copy of the array, then the correct values are printed...
Alternatively, and probably the better solution, is to return the solution instance itself so that it is no longer tied to the scope of
run_outer
Future Fix
It is hard to know the solution to this problem that is not one of the workarounds mentioned above. We want
RadialSolverSolution
to own the heap memory otherwise its owner may never free it properly. The downside is a situation like this where it is deallocated too early.Certain open to suggestions but for now this probably just requires updates to the documentation.
The text was updated successfully, but these errors were encountered: