Recursive functions: Memory leak?

1 Ansicht (letzte 30 Tage)
Mathias Lindner
Mathias Lindner am 4 Feb. 2019
Bearbeitet: Mathias Lindner am 4 Feb. 2019
Hi there,
I have written an algorithm using recursive calculation. What it is actually doing is:
  1. Finding a possible technical solution to a problem.
  2. If this solution is good, find the next possible solution starting from this.
  3. If this solution is bad, go one back and find the next possible solution.
Thus, it is some kind of tree with a lot of "dead ends" and a few good branches.
The calculation is maximum a few dozen recursive calls deep. In the current example it is even only 16 calls deep (so subsequent branches in the tree). However, the amount of possible parallel solutions could also be in the region of a few dozen on every level of recursive call (so parallel branches in the tree). This gives quite a lot of possible combinations.
Now the problem: since the deepnes of the recursive calls is not that high, I have expected the memory usage to be ok. I anticipated that the memory usage of every function call should be freed as soon as the algorithm goes "one step backwards". I only use local variables in the subfunctions. However, when I start the program the initial memory usage is quite ok but it is adding up and adding up - just as if the recursion would go deeper and deeper. But I have double-check, it is not. It just looks like the memory is not freed anymore.
Before I take the hard way and re-write all this code to loops instead of recursion I want to ask if there is any pitfall regarding recursion (or function calling) and memory leakage. Is this a known problem and what can I do against it?
Thank you!
Matlab version: R2015b

Antworten (0)

Produkte


Version

R2015b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by