It seems that you may be leaking a fair amount of memory. Remember that in C++ (unlike Java) you can’t just new something (like a string or array of char) and then forget about it and expect a garbage collector to clean up after you. You need to be more deliberate about your allocations. Such as:
char* System451::Communication::Dashboard::ZomBTCPSource::readBytes(int number)
{
char* buf = new char[number+1];
...
Or:
void System451::Communication::Dashboard::ZomBTCPSource::sendreader()
{
...
curvalues*new string(buf)] = const_cast<const char*>(vbuf);
...
On top of that, creating a new “string” allocates even more memory to copy the heap-allocated char] into and then leaks the char].
Any time you are done with a heap-allocated ("new"ed) variable, you should delete it. Such as here:
int System451::Communication::Dashboard::ZomBTCPSource::readByte()
{
char r = this->readBytes(1)[0];
...
And technically when you new an array, you should use an array delete (“delete ] buf;”), though with a primitive type (char) I don’t think it makes a practical difference. Such as:
char* System451::Communication::Dashboard::ZomBTCPSource::readBytes(int number)
{
...
delete buf2;
...
Also, you are using a map to store the values. Maps don’t allow you to add a value if its key is already present in the map. That means that if it is possible for you to get an updated value instead of always adding new values, then you need to delete the old value from the map before adding the new one. Otherwise you leak both the new name “string” and the old value char].
You are returning a C++ allocated string back to Java and depending on it sticking around. That’s a safe assumption I guess if you never delete anything, but you really should be deleting them when they change. The way this is typically done is to allocate a buffer in Java, pass that out to the “GetString” function, and strcpy the value into the Java string. This way Java is in control of the lifetime of that allocated memory. If you are worried about the string length, then you can split the C entry-point into 2 parts and request the length first and then allocate a buffer in Java and then get the string.
I wouldn’t be surprised if things were dying as a result of some of these memory allocation issues.
-Joe