@@ -58,7 +58,11 @@ STATIC mp_uint_t gc_alloc_table_byte_len;
5858#if MICROPY_ENABLE_FINALISER
5959STATIC byte * gc_finaliser_table_start ;
6060#endif
61- STATIC mp_uint_t * gc_pool_start ;
61+ // We initialise gc_pool_start to a dummy value so it stays out of the bss
62+ // section. This makes sure we don't trace this pointer in a collect cycle.
63+ // If we did trace it, it would make the first block of the heap always
64+ // reachable, and hence we can never free that block.
65+ STATIC mp_uint_t * gc_pool_start = (void * )4 ;
6266STATIC mp_uint_t * gc_pool_end ;
6367
6468STATIC int gc_stack_overflow ;
@@ -153,13 +157,6 @@ void gc_init(void *start, void *end) {
153157memset (gc_finaliser_table_start ,0 ,gc_finaliser_table_byte_len );
154158#endif
155159
156- // allocate first block because gc_pool_start points there and it will never
157- // be freed, so allocating 1 block with null pointers will minimise memory loss
158- ATB_FREE_TO_HEAD (0 );
159- for (int i = 0 ;i < WORDS_PER_BLOCK ;i ++ ) {
160- gc_pool_start [i ]= 0 ;
161- }
162-
163160// set last free ATB index to start of heap
164161gc_last_free_atb_index = 0 ;
165162