VisionSystemsInc / terra

Terra - Run your algorithm anywhere on earth
MIT License
0 stars 3 forks source link

Memory leak #151

Closed andyneff closed 1 year ago

andyneff commented 1 year ago

Finally tracked down a solution to the leak

C++ threw an exception which means the destructor for variables in bsgm_prob_pairwise_dsm::process/compute_min_max_disparity_from_height doesn't get called right away. Instead it stays on the heap for a while, meanwhile the python wrapper object for bsgm_prob_pairwise_dsm gets collected in a python exception traceback frame, keeping the ref count at one never allowing bsgm_prob_pairwise_dsm to be garbage collected. When the executor context ends, all this memory would have freed up, however if you run out of memory before that, it all fails.

The solution is to just clear the frames of the tracebacks, and the only universal method I could find to do that was by adding a callback function to the Future object.

This will unfortunately make attaching a post mortem debugging for an exception in a task harder, But normal set_traceing will still work as intended.