New Framework Memoryblock Memory Leak

OK, I finished converting my arbitrary precision calculator to the new framework on the Mac and I thought all was well. Everything seemed to work. However when I began working with large numbers (million digits) I quickly received an Out of Memory Exception. In my code, I converted old framework memory blocks to new framework memory blocks, strings to text, and used new math methods. I suspected that memory blocks were the culprit since it exhausted memory so quickly so I created a test case where I called a method create_memory_block 10000 times with the following line:

dim mb1 as new Xojo.Core.MutableMemoryBlock(1000000)

I get an out of memory exception if the line is:

dim mb1 as new Xojo.Core.MutableMemoryBlock(1000000)

or

dim mb1 as new Xojo.Core.MemoryBlock(1000000)

but not using the old framework

dim mb1 as new MemoryBlock(1000000)

I filed a feedback <https://xojo.com/issue/37833> with the test code attached.

From the docs of Xojo.Core.MemoryBlock:

The MemoryBlock does not take ownership of the memory, so the application is responsible for freeing it after the MemoryBlock has been destructed.

But I don’t know how to do it. Maybe by using free from the C standard library?

[quote=161155:@Eli Ott]From the docs of Xojo.Core.MemoryBlock:

The MemoryBlock does not take ownership of the memory, so the application is responsible for freeing it after the MemoryBlock has been destructed.

But I don’t know how to do it. Maybe by using free from the C standard library?[/quote]

This is only true when you create a MemoryBlock from a pointer.