You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When calling begin() after the receive and transmit buffers have been allocated, the begin function orphans the allocations by resetting the pointer to nullptr, on the next call of allocateTxBuffer(), we get a new memory allocation while the previous one has never been freed, this in turns causes heap segmentation and will lead to lack of memory in the long run.
Yeah I agree, this is dummy code, but my philosophy is that Arduino should be dummy proof. This became an issue for me because I had locally scoped a sensor object(I know this was stupid...), destroying and creating it every time caused it to call begin and in turn cause the memory leak.
Activity
fpistm commentedon Jul 16, 2024
Hi. In fact your code is wrong. You have to call
Wire.end();This is like you call malloc each loop iteration without calling free.
benmalenfant commentedon Jul 16, 2024
Yeah I agree, this is dummy code, but my philosophy is that Arduino should be dummy proof. This became an issue for me because I had locally scoped a sensor object(I know this was stupid...), destroying and creating it every time caused it to call begin and in turn cause the memory leak.