# 0.6.6: Memory Management Improvements

DevFeed: [0.6.6: Memory Management Improvements](<https://devfeed.tech/articles/0-6-6-memory-management-improvements-22390.md>)

Original publisher: [Read original article](<https://www.red-lang.org/2025/03/066-memory-management-improvements.html>)

Author: Nenad Rakocevic (noreply@blogger.com)

Published: 2025-03-19T16:11:00Z

Content type: release

Language: en

Sources: [Red](<https://devfeed.tech/sources/red.md>)

Topics: [Memory Safety](<https://devfeed.tech/topics/memory-safety.md>), [Memory Leaks](<https://devfeed.tech/topics/memory-leaks.md>)

Tags: [external](<https://devfeed.tech/tags/external.md>), [font](<https://devfeed.tech/tags/font.md>), [fonts](<https://devfeed.tech/tags/fonts.md>), [gc](<https://devfeed.tech/tags/gc.md>), [images](<https://devfeed.tech/tags/images.md>), [improvements](<https://devfeed.tech/tags/improvements.md>), [management](<https://devfeed.tech/tags/management.md>), [memory](<https://devfeed.tech/tags/memory.md>), [memory-management](<https://devfeed.tech/tags/memory-management.md>), [memory-model](<https://devfeed.tech/tags/memory-model.md>), [resources](<https://devfeed.tech/tags/resources.md>), [series](<https://devfeed.tech/tags/series.md>)

## AI overview

Red 0.6.6 improves memory management by adding cleanup for external resources and making garbage-collector stack scanning more precise. A new manager tracks resources such as image bitmap buffers and font handles associated with unreachable face! or font! objects and frees them. Previously, the conservative native-stack scanner could mistake floating-point values for pointers, risking rare corruption or crashes, and could not support node-frame collection. The R/S compiler now emits bit-array hints identifying arguments and local variables that may hold series or node pointers; function calls push an offset so the scanner can find the matching map and examine only marked stack slots. The excerpt cuts off during the explanation of how those slots are further analyzed.

## Source excerpt

This new milestone brings many low-level improvements to Red's memory management and garbage collecting. Most of those are long-planned additions needed to complete the internal memory model and make it robust enough for the future stable Red v1.0. First, here is a simplified overview of the Red memory model (existing parts in green color, new parts in orange, non-Red parts in blue): All Red values are stored in series. Some Red values require one or more buffers to hold their content. The values can never reference a buffer directly, but only through a node reference, to enable relocation when expanding the series buffer or when moving it around during compaction by the GC. Now let's dive into the hairy details! External resources GC The Red/View engine backends rely on external resources provided by the OS. Among those resources, some are linked to face! or font! object and require special care when those objects are not reachable anymore. So far, our GC (Garbage Collector) was not able to release such resources (images bitmap buffers and fonts handles), as unreachable Red aggregate values are seeing as simple series during the sweeping GC stage. In order to improve that, we have added an external resources manager, that will track and free unused resources, allowing now unrestricted images and fonts usage! Accurate GC The Red GC relies on allocated memory walking and native stack scanning to identify live Red values. Scanning the native stack can be challenging. The scanner used so far a conservative approach, which is simpler, but can lead to corruptions or crashes in rare cases (e.g. a floating point number being mistaken for a series or node pointer). Moreover, such approach precluded from having a nodes frame GC, as there was no way to accurately identify node pointers on the stack. This is now solved. The plan was always to make it precise when getting closer to a Red v1.0 and that's what we did in this release. In order to achieve that, several key addition