seems like handles are leaking memory

Apr 8, 2013 at 8:02 PM
hi Keith,

hope you are doing well. i wrote this simple code to create handles

static AddInX xai_test1(FunctionX(XLL_HANDLEX, _T("?xll_test1"), _T("test1"))
.Arg(XLL_LPOPERX, _T("arg1"), _T("arg1"))
.Uncalced()
.FunctionHelp(_T("creates handle")));

HANDLEX WINAPI
xll_test1(LPOPERX xarg1)
{

pragma XLLEXPORT

HANDLEX h;
try 
{
    handle<double> h1(new double(0.));
    h = h1.get();

}
catch (const std::exception& ex) 
{
    XLL_ERROR(ex.what());
}

return h;
};

then in the debugger i stop at
        handle_set& h(handle_set_get());
        T* q = previous();
inside static void insert(T* p, D d) to see what handles are getting created and deleted.

I observe that each time i make the call the handle_set h keeps growing. i thought if i repeatedly keep calling "test1" from the same cell the handle_set h should not grow ?

any comments ?

Best
Coordinator
Apr 9, 2013 at 1:57 AM
You are correct, kaushikmatia. It never occurred to me that someone would allocate useless null handles.

The great thing about open source software is that you have the opportunity to fix this if you find it important.
Apr 9, 2013 at 2:07 AM
well slightly more useful handles are also leaking it seems. like when you have :

handle<std::vector<double> > h1(new std::vector<double>(10000,0.));
Coordinator
Apr 9, 2013 at 2:30 AM
I spent time looking at your last claim. And others you made. Convince me this one is real.
Apr 9, 2013 at 2:50 AM
following is the experiment i did which led to the post. same code as above then in the debugging mode i kept evaluating the function. also i was observing the memory used by excel using the task manager. i observed everytime i evaluated the funtion the memory kept on increasing. that should not be happening should it ? more over in the handle_set h kept growing (as many times as i evaluated the function). also i was evaluating the function by clicking the fx button and then clicking ok in the function wizard. this experiment is replicable i guess.
Apr 9, 2013 at 12:47 PM
well slightly more useful handles are also leaking it seems. like when you have :

handle<std::vector<double> > h1(new std::vector<double>(10000,0.));
Apr 9, 2013 at 12:47 PM
well slightly more useful handles are also leaking it seems. like when you have :

handle<std::vector<double> > h1(new std::vector<double>(10000,0.));
Coordinator
Apr 9, 2013 at 1:29 PM
If you keep F2-ing a cell, Excel can't find the old handle. Move the cursor to a different cell and type Ctrl-Alt-F9 and you will see the old handle gets deleted.
Apr 9, 2013 at 3:14 PM
okay i see the that handles are getting deleted when i press cltr-alt-f9. but it is interesting that if a user presses the "fx" button and hits "ok" (with the intention of just calculating a cell formula) the handle will keep building. take for instance a situation where there are two slow computing formulas with huge data some one would want to compute just one formula (and use the function wizard) instead pressing cltr-alt-f9 and would run into this issue. anyway....

by the way the i wonder how the two 7:47 AM post came up as i was not even close to a computer at that time. funny that this thing happened on a discussion about handles building up...
Coordinator
Apr 9, 2013 at 3:34 PM
You can use in_function_wizard() to detect if the add-in is being called from the Function Wizard.
Apr 9, 2013 at 3:47 PM
not sure what you are suggesting. i do use in_function_wizard() to detect if addin is being called from the function wizard.