Serving the Quantitative Finance Community

 
User avatar
hazerider
Topic Author
Posts: 0
Joined: July 24th, 2003, 3:45 pm

XLW memory leak

June 3rd, 2011, 2:33 pm

I know a lot of the people who maintain XLW are frequent contributors here, so I am hoping this is the best place to ask this question.I've been using XLW for a long time and it works beautifully (version 3.0.0f). However, I encountered a memory-leak problem, which only shows up intermittently. This particular function uses ADO to run a query against a SQL Server and returns the results in the spreadsheet. For certain queries, it shows a heap allocation error. In debug mode, it breaks in XlfExcel::FreeMemory, on the line "delete[] freeList_.back().start;". It doesn't seem like it does anything wrong. I can even ignore the error (when the dialog with "Abort|Retry|Ignore" shows up), and everything keeps working as it's supposed to. The particular query exhibiting the behavior doesn't even return that much data, it's about 300 rows and 3 columns. For that size CellMatrix, XlfExcel::GetMemory is requesting in the neighborhood of 60K bytes. If I change the initial buffer size to 256K, the error disappears. The other thing I discovered is that it seems related to how I am reading strings returned by ADO. The ADO type for those is adVarChar, which is represented as a BSTR, which is typedef'ed as a wchar_t *. If I just return a constant string instead of converting the BSTR to a std::string (using WideCharToMultiByte), the problem goes away as well.I guess my questions are the following:- has anyone experienced any similar behavior? How did you solve it?- would switching over to version 4 get rid of this problem?- is the solution I came up with (increasing the initial buffer size) a real solution or will it just make the problem appear less often?Thanks,Marc.
 
User avatar
adcockj
Posts: 1
Joined: July 14th, 2002, 3:00 am

XLW memory leak

June 4th, 2011, 8:02 pm

I did see something similar while i was looking at some multi-threading issues, there did seem to be a couple of issues with the memory allocation code in versions 3&4. Probably you best bet is to try the latest release from the dev5 branch and see if it reoccurs. Are there any multi-threaded functions in your xll? If not it may well be to do with buffer size as you've found, i think that your fix will be ok in the very short term but yes it is probably just hiding the issue with your current memory load. John
 
User avatar
hazerider
Topic Author
Posts: 0
Joined: July 24th, 2003, 3:45 pm

XLW memory leak

June 6th, 2011, 11:21 am

Nope, nothing multi-threaded in my code. It's really strange because this problem only manifests itself very rarely, I think it's only happened twice in the past 2 years.
 
User avatar
adcockj
Posts: 1
Joined: July 14th, 2002, 3:00 am

XLW memory leak

June 7th, 2011, 6:45 am

Hmmm, it may be related to the string functions then, there were a few issues in there, also fixed in the Dev5 code. Would it be possible to test with that?John
 
User avatar
hazerider
Topic Author
Posts: 0
Joined: July 24th, 2003, 3:45 pm

XLW memory leak

June 7th, 2011, 11:25 am

I wish I could tell you I will definitely test it, but unfortunately I might not get to it for a while. I will most likely try it though if the problem happens again. Thanks.