Implemented workaround to prevent multiple function invocations cumulating memory leaks up to the point they were effectively crashing