-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Potential memory leak #14
Comments
Hi sreekants, I had this issue recently and yes you must call rc.close() every cycle to release the memory. I have also suggested it be added to the example code. Maybe a better approach is to allocate the maximum allowable per message ie 256 bytes and then leave it allocated for ever? |
I like the idea of a pre-allocated buffer managed by the library. That would be a good fix with backward compatibility if the close() function has an empty body. |
Hi all, |
Hi Renzo, EByte_LoRa_E22_Series_Library/LoRa_E22.cpp Line 780 in 510e04e
Can you explain how the heap is managed correctly with the library? (We arrived at this problem because we were transmitting 220 byte frame over LoRa E22 in our software and when we monitored the heap it fell from 180Kb, steadily to 70kb as our stress tests ran through a few hours.) |
Hi @sreekants, EByte_LoRa_E22_Series_Library/LoRa_E22.cpp Lines 777 to 795 in 510e04e
and It had It EByte_LoRa_E22_Series_Library/LoRa_E22.h Lines 228 to 235 in 510e04e
but the ResponseContainer doesn't have and doesn't need a close. EByte_LoRa_E22_Series_Library/LoRa_E22.h Lines 228 to 240 in 510e04e
Bye Renzo |
Yes, I understand now. I stand corrected. Your samples use ResponseContainer. So they do not need a close(). You are correct there. In our usecase, however, we are sending binary data over LoRa. The ResponseContainer is suitable only for string data. This is why we end up calling receiveMesssageComplete(). As stated, each call allocates a buffer, fragmenting memory, even if the close() function is called. Is there a better way to allow the use of a preallocated buffer so we don't have to malloc() every loop? |
Ahhh ok, now I understand, |
I think I asked that question and you made some update and then I share a video about this issue 2 years ago #8 |
In LoRa_E22.cpp a buffer is allocated in each call
...
ResponseStructContainer LoRa_E22::receiveMessageComplete(const uint8_t size, bool rssiEnabled){
ResponseStructContainer rc;
However, in all of the samples, you appear not to release the memory, for example esp32_e22_04_SendFixedTransmission.ino:
...
if (e22ttl.available()>1) {
// read the String message
#ifdef ENABLE_RSSI
ResponseContainer rc = e22ttl.receiveMessageRSSI();
#else
ResponseContainer rc = e22ttl.receiveMessage();
#endif
...
Isn't rc.close() required to release the memory? Also, is there a way to avoid malloc() every time you receive a message to avoid fragmentation?
The text was updated successfully, but these errors were encountered: