Free dynamically allocated memory by Excel XLL when all dependent cells are calculated

  c++, excel, memory-management, xll

My Excel XLL written in C++ exports functions that allocate lots of memory and return references as strings to the allocated data. These references can be passed to other functions as arguments in other cells and eventually a number is produced as a final result.

Is there a way to know when Excel evaluated all dependent formulas so that my XLL can free the memory associated with the given reference? That would allow the users to create bigger spreadsheets because the memory can be freed while worksheet calculations are happening.

There’s xlAutoFree, but it seems to be called just after returning a value, not when all dependent cells finished evaluating.

If that’s not possible, are there any other ways to achieve something similar?

Source: Windows Questions C++