SCM20260N Memory

I am running out of memory. The spec sheet shows 32MB RAM.
Why do I not see all that I used

var freeRam = GHIElectronics.TinyCLR.Native.Memory.ManagedMemory.FreeBytes;
var usedRam = GHIElectronics.TinyCLR.Native.Memory.ManagedMemory.UsedBytes;

and the log show only a usage of 500KB

PR: 06/04/2022 04:13:42: G Clean
PR: 06/04/2022 04:13:42: Used: 500976 Free: 6816
PR: 06/04/2022 04:13:42: Graph
The thread ‘’ (0x1d) has exited with code 0 (0x0).
Failed allocation for 71 blocks, 1136 bytes

Did you enable external ram?

Did not know that I have to do it. Do I just run this at statup?

GHIElectronics.TinyCLR.Native.Memory.ExtendHeap()
GHIElectronics.TinyCLR.Native.Power.Reset();

yes, but you should check if the heap is already enabled or your board keeps resetting.

if (IsExtendHeapEnabled == false) {
GHIElectronics.TinyCLR.Native.Memory.ExtendHeap()
GHIElectronics.TinyCLR.Native.Power.Reset();
}

Look at API in our doc, I don’t remember exactly but something like that.

Also, this is not really out of memory, this is sign of memory fragment. You need to check this:
Memory Management (ghielectronics.com)

section Garbage Collection, Finalizers

But there is no memory to free
Used: 500976 Free: 6816

try this before enabling external ram to see if any different.

Adjust MEM_CHECK to fit your project,

const int MEM_CHECK = 50 * 1024; // 50KB
new Thread(() =>
            {
                if (GHIElectronics.TinyCLR.Native.Memory.ManagedMemory.FreeBytes < MEM_CHECK)
                {
                    System.GC.Collect();
                    System.GC.WaitForPendingFinalizers();
                }

                Thread.Sleep(10);
            }
            ).Start();

ok…Thanks that helped

        if (GHIElectronics.TinyCLR.Native.Memory.IsExtendedHeap() == false)
        {
            GHIElectronics.TinyCLR.Native.Memory.ExtendHeap();
            GHIElectronics.TinyCLR.Native.Power.Reset();
        }