The embedded Linux system I have has 28K RAM and 31.6M of flash which the file system is mounted on. I developed an application that needs to run continuously inside the embedded Linux. The problem is that the virtual storage size (VSZ in top
command) for the application keeps increasing until the system crashes. If I understand things right and correct me If I'm wrong, VSZ should vary depending on the memory allocation done by the program and if the memory is freed it should go to the previous value and stay constant.
The program uses the following declaration in the source code:
1- A vector of struct pointers:
vector<Struct*> someVector; // Struct pointers are initialized with new
// After the previous vector has some values, it is freed like this
for(unsigned i = 0; i < someVector.size(); i++)
{
delete someVector[i];
}
someVector.clear();
vector<Struct*>().swap(someVector);
2- A vector of strings, same as before but instead of the delete
inside the loop I do: someVector[i] = "";
3- char*
char* somePointer = (char*) malloc(100);
free(somePointer);
somePointer = NULL;
4- Sometimes I use fstream*
initialized with new
I don't think it will make any difference as C++ objects will be destroyed once out of the scope.
5- char** array = new char*[100];
This is deleted by delete[] array
. I used delete
on the internal elements but valgrind
gives me Mismatched free/delete
or something similar.
NOTE: The source is big and these are the most data structure that the application use. If there is anything else suspicious I will do an update
I compile the application and move it to the embedded device using SSH, I run the application and monitor top
command output; the VSZ value for application's process keeps increasing until a large value like 11K and the system crashes. I'm pretty sure every allocation I do I have the corresponding free mechanism (free, delete
, etc).
valgrind ./myApplication
tool does not show even a warning message, Should I assume that allocation and deallocation is done safely ?
Any help is appreciated. I'm available immediately for any info required. Thanks In advance!
Update 8/4/2015: The process that increases the VSZ of the application is gathering data and storing them in files on the flash memory continuously, there is a mechanism to check for exceeding size but I do not use it now. Could this be related ?