#60: Fix memory leaks in k_order_perturbation DLL --------------------------+------------------------------------------------- Reporter: sebastien | Owner: george Type: bug | Status: new Priority: minor | Milestone: Component: K-order DLL | Version: Resolution: | Keywords: --------------------------+-------------------------------------------------
Comment(by sebastien):
Basically, the problem is that the current k-order code creates objects at several places (using "new" operator) without ever deleting them. This creates memory leaks, which are not a big issue in typical situations, but which can become problematic when for example running the code several times inside a loop, since memory consumption will grow and never decrease.
In my opinion, the use of pointers is a bad practice, and should be restricted to very rare cases. Objects should be allocated on the heap (by the calling function in the case of an output variable of a subfunction), or as data members of classes, but never (or so) by using "new" or "malloc". That way, memory will always be correctly deallocated, and many potential errors (such as seg faults) are avoided.
Fixing this in k_order_perturbation DLL implies to change the interface of several functions, in particular those who use pointers for input or output arguments. Passing-by-reference should be used for both input and output (using a "const" for inputs).