Something to be aware of if you're using an ESP32 with PSRAM -- MicroPython takes ownership of the PSRAM directly (i.e. outside of ESP32's malloc) and uses it directly for the GC heap (see esp32/main.c). So if you're using heap_caps_malloc to allocate in PSRAM then it's definitely going to be clobbered by the GC.elliotwoods wrote: ↑Tue Jul 14, 2020 9:47 amSo we can confirm that the GC shouldn't touch memory which is created by the platform's own malloc (e.g. ESP32 heap_caps_malloc).
In general though -- anything you allocate statically or via platform malloc (if you have one, which most ports don't), will not be affected by the GC. As has been pointed out, the main issue is that something you alloc with the GC (i.e. via m_new*) must be referenced in a way that the GC can find (e.g. via the port's root pointers, or the pointer to this alloc must be a member of some other structure that is itself reachable by the GC, e.g. it's a Python object).