Teensy 3.1: Problem with memory deallocation

Status
Not open for further replies.

maxbot

Active member
Hello guys,
I have a problem on my newest project with the Teensy 3.1:
I want to use a big array of float temperatures (size 6000) in order to put them into a gaussian blur function.
So my method starts like this:
Code:
void ImageCreation(float** temperatures, bool save) {
	Serial.print("Free ram before allocation:");Serial.println(FreeRam());
	float* filtertemp = (float*) malloc(6000*sizeof(float));
        ...
In the middle it does some operations with the array and finally I want to free it:
Code:
        ...
        free(filtertemp);
        Serial.print("Free ram after deallocation:");Serial.println(FreeRam());
	//Close the files
	if (combinedImage)
		bmpFile.close();
	if (save)
		thermalImage.close();
}

The method FreeRam() prints me the RAM usage of the Teensy. Now the weird part comes:
Code:
Free ram before allocation: 39911
Free ram after de-allocation: 15335

So for some reasons, the memory is not deallocated correctly. This leads to allocation issues if I call the method again at a later point.
Can anyone help me how to solve this problem ?
Thanks !
 
I suspect that the FreeRam() routine only reports the unfragmented heap's free memory remaining. In addition to this memory, is a "chain" of memory fragments that have been freed.

If you were to request that exact same allocation, you'll likely get the same memory pointer back and your FreeRam() stats won't [likely] change (assuming no other library calls have allocated memory).
 
Status
Not open for further replies.
Back
Top