Skip to content

Commit 724f018

Browse files
committed
py,ports/stm32: Remove GC test instrumentation causing MemoryErrors.
Remove gc_recently_run and gc_last_run_ms test instrumentation variables and GC_MIN_INTERVAL_MS logic that was added during debugging. These checks prevented normal GC behavior and caused MemoryError failures in production. The GC now runs normally based on MICROPY_GC_ALLOC_THRESHOLD without artificial delays or double-GC prevention, restoring standard MicroPython garbage collection behavior. Signed-off-by: Andrew Leech <andrew@alelec.net> Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
1 parent 2032aa2 commit 724f018

File tree

3 files changed

+4
-44
lines changed

3 files changed

+4
-44
lines changed

ports/stm32/gccollect.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,4 @@ void gc_collect(void) {
4848

4949
// end the GC
5050
gc_collect_end();
51-
52-
// TEST: Clear flag after explicit gc.collect() (allow future allocations)
53-
gc_recently_run = false;
54-
55-
// TEST 4: Update timestamp after explicit GC
56-
gc_last_run_ms = mp_hal_ticks_ms();
5751
}

py/gc.c

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -762,13 +762,6 @@ void gc_info(gc_info_t *info) {
762762
GC_EXIT();
763763
}
764764

765-
// TEST: Track recent GC to prevent rapid double-GC
766-
bool gc_recently_run = false;
767-
768-
// TEST 4: Add minimum delay between GC cycles (allow threads to resume)
769-
uint32_t gc_last_run_ms = 0;
770-
#define GC_MIN_INTERVAL_MS 100
771-
772765
void *gc_alloc(size_t n_bytes, unsigned int alloc_flags) {
773766
bool has_finaliser = alloc_flags & GC_ALLOC_FLAG_HAS_FINALISER;
774767
size_t n_blocks = ((n_bytes + BYTES_PER_BLOCK - 1) & (~(BYTES_PER_BLOCK - 1))) / BYTES_PER_BLOCK;
@@ -798,19 +791,10 @@ void *gc_alloc(size_t n_bytes, unsigned int alloc_flags) {
798791

799792
#if MICROPY_GC_ALLOC_THRESHOLD
800793
if (!collected && MP_STATE_MEM(gc_alloc_amount) >= MP_STATE_MEM(gc_alloc_threshold)) {
801-
// TEST 4: Check if minimum delay elapsed since last GC
802-
uint32_t now_ms = mp_hal_ticks_ms();
803-
if (now_ms - gc_last_run_ms >= GC_MIN_INTERVAL_MS || gc_last_run_ms == 0) {
804-
GC_EXIT();
805-
gc_collect();
806-
collected = 1;
807-
gc_recently_run = true; // Mark GC as having run
808-
gc_last_run_ms = now_ms; // Update last GC timestamp
809-
GC_ENTER();
810-
} else {
811-
DEBUG_printf("gc_alloc(" UINT_FMT "): skipping GC (only %u ms since last)\n",
812-
n_bytes, (unsigned)(now_ms - gc_last_run_ms));
813-
}
794+
GC_EXIT();
795+
gc_collect();
796+
collected = 1;
797+
GC_ENTER();
814798
}
815799
#endif
816800

@@ -857,18 +841,9 @@ void *gc_alloc(size_t n_bytes, unsigned int alloc_flags) {
857841
#endif
858842
return NULL;
859843
}
860-
// TEST 4: Check if minimum delay elapsed since last GC (emergency collection)
861-
uint32_t now_ms = mp_hal_ticks_ms();
862-
if (gc_recently_run || (now_ms - gc_last_run_ms < GC_MIN_INTERVAL_MS && gc_last_run_ms != 0)) {
863-
DEBUG_printf("gc_alloc(" UINT_FMT "): skipping second GC (recent=%d, delay=%u ms)\n",
864-
n_bytes, gc_recently_run, (unsigned)(now_ms - gc_last_run_ms));
865-
return NULL; // Fail allocation instead of running second GC
866-
}
867844
DEBUG_printf("gc_alloc(" UINT_FMT "): no free mem, triggering GC\n", n_bytes);
868845
gc_collect();
869846
collected = 1;
870-
gc_recently_run = true; // Mark GC as having run
871-
gc_last_run_ms = now_ms; // Update last GC timestamp
872847
GC_ENTER();
873848
}
874849

@@ -941,9 +916,6 @@ void *gc_alloc(size_t n_bytes, unsigned int alloc_flags) {
941916
gc_dump_alloc_table(&mp_plat_print);
942917
#endif
943918

944-
// TEST: Clear flag on successful allocation (allow future GCs)
945-
gc_recently_run = false;
946-
947919
return ret_ptr;
948920
}
949921

py/gc.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,4 @@ void gc_info(gc_info_t *info);
8484
void gc_dump_info(const mp_print_t *print);
8585
void gc_dump_alloc_table(const mp_print_t *print);
8686

87-
// TEST: Flag to track if GC recently ran (prevent rapid double-GC)
88-
extern bool gc_recently_run;
89-
90-
// TEST 4: Timestamp of last GC (for minimum delay enforcement)
91-
extern uint32_t gc_last_run_ms;
92-
9387
#endif // MICROPY_INCLUDED_PY_GC_H

0 commit comments

Comments
 (0)