Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By eldonb46
#22504 I have a WebServer Sketch that reports "ESP.getfreeheap()", the value of which it typically 19K bytes.

I have noticed that when the reported value falls below about 17K bytes, the WebServer starts to fail or resets.

Questions:

1. How much "freeheap" is actually necessary, and are there any tools that can show how it is being used or fragmented? What would be necessary to implement a more informative API?

2. Are there tools to report "Garbage Collection" activities?

3. Does Arduino "String" type variable grow and shrink with use, or only shrink via Garbage Collection?


And Yes I know I am maybe trying to "shoehorn" too much functionality into a small space, but I want to be smart about it.

Thanks,
Eldonb46 - WA0UWH
User avatar
By kolban
#22505 In the C programming language, there is no garbage collection ... simply because there are no object creations. C is not an Object Oriented language and any and all data created by a C program is explicitly allocated. In typical C environments, one allocates memory using a function called malloc() which takes as a parameter the number of bytes of storage to allocate. This is allocate from the heap. When the storage that was allocated by a call to this function is no longer needed, it is the programmers responsibility to explicitly release the storage with a call to free() that takes a pointer to the storage returned by malloc().

This does not mean that it is not possible to have memory leaks. A bad program or incorrect usage of a memory allocation can result in requests to allocate storage but failure to return it when done. This causes the free heap space to continually shrink.
User avatar
By eldonb46
#22507
kolban wrote:In the C programming language, there is no garbage collection ... simply because there are no object creations. C is not an Object Oriented language and any and all data created by a C program is explicitly allocated. In typical C environments, one allocates memory using a function called malloc() which takes as a parameter the number of bytes of storage to allocate. This is allocate from the heap. When the storage that was allocated by a call to this function is no longer needed, it is the programmers responsibility to explicitly release the storage with a call to free() that takes a pointer to the storage returned by malloc().

This does not mean that it is not possible to have memory leaks. A bad program or incorrect usage of a memory allocation can result in requests to allocate storage but failure to return it when done. This causes the free heap space to continually shrink.


Kolban, Thanks for the insite, I am still learning C and C++.

I thought most of the libraries and underlying support for ESP via the Arduino IDE (which I use) was writen in C++, including the "String" construct. and therefore my questions. I may be wrong, . . . but still learning :-)

Eldonb46 - WA0UWH
User avatar
By tytower
#22508
C is not an Object Oriented language
Its a fruitless debate but I disagree with that. All languages can be used as OO . In particular C++ is so orientated and C++ is what is used in the Arduino IDE. Lets not get into this any deeper though .

I would like to see if any members come up with an answer to ESP.getfreeheap() and what it can be used for . I don't know, but I assume it will tell me how much programming space I have left on my chip. When I upload my program to the chip it has a set size in bytes and being in hex I assumed it could not get any bigger. Am I wrong in that assumption . can it increase in any way?
Last edited by tytower on Sun Jul 05, 2015 3:10 pm, edited 2 times in total.