Several people have mentioned microPython on this forum and I started checking it out. I’m not going to dump C# anytime soon but it does have some nice functionality controlling the garbage collector. I’ve been successful at using think .Net Micro in real time applications on the order of tenths or even hundredths of a second as long as I can keep the GC from running. I can do that by 1) being careful about where I use the new operator and 2) Never using string operations anywhere I need real time response. But it sure would be easier if I had the functionality that microPython provides to control the GC.
Here’s the link to the documentation
and here’s a summary of the functionality:
gc – control the garbage collector
gc.enable(): Enable automatic garbage collection.
gc.disable(): Disable automatic garbage collection. Heap memory can still be allocated, and garbage collection can still be initiated manually using gc.collect().
gc.collect(): Run a garbage collection.
gc.mem_alloc() Return the number of bytes of heap RAM that are allocated.
gc.mem_free() Return the number of bytes of available heap RAM, or -1 if this amount is not known.
gc.threshold([amount]) Set or query the additional GC allocation threshold. Normally, a collection is triggered only when a new allocation cannot be satisfied, i.e. on an out-of-memory (OOM) condition. If this function is called, in addition to OOM, a collection will be triggered each time after amount bytes have been allocated (in total, since the previous time such an amount of bytes have been allocated). amount is usually specified as less than the full heap size, with the intention to trigger a collection earlier than when the heap becomes exhausted, and in the hope that an early collection will prevent excessive memory fragmentation. This is a heuristic measure, the effect of which will vary from application to application, as well as the optimal value of the amount parameter.