Manual memory
To know where memory comes from in Meem, and when you give it back yourself.
For beginners
Section titled “For beginners”- Every string you build, and every list and dictionary, takes a place in memory from an allocator, which is where memory is taken from and given back to. If you name no allocator, the allocation comes from the default allocator.
- Since 0.7, Meem has neither reference counting nor a garbage collector. Whatever is not freed returns to the system when the program exits.
- So a short program needs nothing. A long program gives back what it is done with:
حرر(س)(free) gives back the string, list or dictionary immediately, and makesسلاشيء.خاتمه جملة(defer) postpones the statement until the block exits, so if you writeخاتمه حرر(ن)in a loop, the space ofنis given back at the end of each round.
لكل ع في مدى(0, 3): ن = "سطر " + نص(ع) خاتمه حرر(ن) اطبع(ن)Freeing the same value twice is a runtime error:
م = جديد(1)حرر(م)حرر(م)Exit code: 3
In the error catalog: E0349
م = جديد(1)حرر(م)اطبع(م == لاشيء)For professionals
Section titled “For professionals”- An arena (
ساحة(الاصل)) is an allocator that collects what is allocated from it, andاعد(ساحه)(reset) gives it all back at once. - The detector (
كاشف(الاصل)) is an allocator that reports what was not freed from it. - In builtins and functions, a last argument of type
مخصص(allocator) is optional, and what the function builds is allocated from it. - The detector is on by default in a direct run (since 0.10.0);
--debug-memadds a report of what was not freed, with the allocation line and the call line, and--debug-mem=failturns whatever is left into a failure with code 4 (since 0.13.0). - Before running (since 0.13.0): the compiler frees temporaries by itself, a local allocation in a function that is neither freed nor passed out of it is compile error E0472 (since 0.14.0), and «لا دليل على تحرير» (no proof of freeing, E0471) is shown with
--warn-unprovenand becomes an error with--strict-memory(since 0.17.0).
The full table, the examples and the limits are in the memory reference: allocators and خاتمه.
What changed since 0.6
Section titled “What changed since 0.6”Release 0.6 counted references, and release 0.7 does not. Details in migrating from 0.6 to 0.7, and the old model is described in reference counting (historical).
See also
Section titled “See also”The beginner’s memory lesson · The low-level layer · Glossary