UDF memory use in Excel

Add-in Express™ Support Service
That's what is more important than anything else

UDF memory use in Excel
UDF Excel memory leak 
Larry X


Serious Developer


Posts: 34
Joined: 2011-04-22
Take a function of the form (in the ActiveX server):

function AFunc(var X1,X2: OleVariant): OleVariant;
var
MyArray: Olevariant;
N: integer;
begin
N := some value;
MyArray := VarArrayCreate([1,1,1,N], varVariant);
...
work done
...
Result := MyArray;
VarClear(MyArray);
end;

As I recalculate this UDF may times in a spreadsheet (in the same cell), Excel's memory use keeps going up in Task Manager. I am reasonably sure there is no memory leak in the code. So what can I do to stop what appears to be a memory leak?

Thank you.
Posted 26 Apr, 2011 16:17:28 Top
Dmitry Kostochko


Add-in Express team


Posts: 2839
Joined: 2004-04-05
Hi Larry,

Please make sure that your code which you omitted in the sample above does not produce memory leaks. As for the Task Manager, this tool shows all memory used by a process but it is not purposed for memory leaks detection.
Posted 27 Apr, 2011 07:09:13 Top
Larry X


Serious Developer


Posts: 34
Joined: 2011-04-22
Hi Dmitry,

Thank you for the reply. I checked that the omitted code does not generate a leak. So my question for you is whether there is still this memory issue with Delphi and DLLs when developing a UDF for Excel using Add-in Express.

Best,

Larry
Posted 27 Apr, 2011 07:24:11 Top
Dmitry Kostochko


Add-in Express team


Posts: 2839
Joined: 2004-04-05
Hi Larry,

I did not see any memory issues in your case. Excel loads your library, searches through the type library for a method (function name entered by the user) and calls your method directly.

If everything is ok in the code of your method then there are no memory leaks. Also, as I mentioned earlier, the Task Manager is not the proper tool for making assumptions about memory leaks. Try to leave Excel alone for some time after recalculation and you will see the volume of used memory decreasing.
Posted 27 Apr, 2011 08:45:45 Top
Larry X


Serious Developer


Posts: 34
Joined: 2011-04-22
Thank you!
Posted 27 Apr, 2011 09:14:57 Top