Does the string you pass in have a maximum size? If so stupid solution would be always pass in the maximum stringsize.
I guessing here but I think the new char*(stringsize) is overloading or creating a new instance of the string object
and on return leaves the old string instance in memory - ignore this just mental muttering to look for a solution
More mental musing.
A char is a single byte a string is a sequence of char ended by a zero.
stringcpy will expect the array of char to be ended by a zero.
I am assuming that *char is a pointer where the char array - cant find reference to this yet and the mlq compiler
is a bastardised(hacked?) version of the C++ compiler (probably for the best too!)
therefore without reading up on what it actually does would char *spar = new char; create a memory allocation of 4 byte referenced by the
*spar pointer. So you have now 'lost' the pointer to the origional string you were passing and hence the memory leak - (At least thats my theory! I can and often am very wrong)
this link may be of use
Could you also post a link to the Exper sample you mention - I can't find it at the moment. thanks in advance
I would have expected that when used like this [...] MT4 would clear the memory from it when finished.
It's odd that MQL4 allows and can interpret char * return values from DLL functions, but does not appear to do garbage collection on the memory. I'd expect it either to do both, or neither. Well-known and widely used libraries on this forum such as http51.dll are vulnerable to this memory leak (though the real-life impact is usually limited).
You basically have two options:
I could be wrong but to be safe I would make new char to allow for the teminating 0 character of a string.
Unless you tell the compiler to use strict array range checking C of itself is not good at checking these things,
but this is ancient memory for for me.
Again not sure this is right but you could deallocate the memory of the old string and then
allocate memory for the new string. and then assign it might achieve the same result.