Forum Discussion
about XLL memory management
Rodrigo_ Thanks for reply. I would like to summarize the usage of xlbitDLLFree as follow
1. xlbitDLLFree is used only in scenario when UDF return a dynamic allocated XLOPER12
2. For the returned XLOPER12, if xlbitDLLFree is set, Excel will pass it back to xlAutoFree12. if not set there will be a memory leak.
there leaves a question, what will happen if XLL did not export xlAutoFree12?
In parallel, can I summarize the usage of xlbitXLFree as follow?
1. xlbitXLFree is used only in scenario when UDF return a dynamic allocated XLOPER12
2. For the returned XLOPER12, if xlbitXLFree is set, Excel will free it including the XLOPER12 itself (I'm especially caring about this, from the official https://learn.microsoft.com/en-us/office/client-developer/excel/memory-management-in-excel#example, it seems there is little chance I'm right), if not set, there will be a memory leak.
(all the dynamic allocated XLOPER12 mentioned above does not contain static allocated memory, for example, val.str is not static allocated).
For writing high performance custom functions I'd recommend using a C++ wrapper to avoid memory management headaches. Options include,
XLL+: https://www.planatechsolutions.com/xllplus/
XLW: https://www.youtube.com/watch?v=k0V6nvWjMnI
Both provide a C++ interface for creating xlls (templates, smart pointers, etc.) the latter being open source.