GOLF(2gg)

πŸ“¦ version 601.4.41, in ubuntu questing

πŸ’– GOLF(2gg) πŸ’–

okay bestie, welcome to the Golf docs β€” this one's the memory page, and honestly? it's giving peace of mind. it lives in the Development corner of the manual, section 2gg. let's get into it 🫢


✨ NAME ✨

memory-handling β€” Golf documentation (memory)

like, that's the whole name. memory-handling. the memory chapter. the vibes. 🧠✨


🌸 DESCRIPTION 🌸

so, the headline: Golf is a memory-safe language. periodt. πŸ’…

your application cannot access memory outside of valid statement results. try it? your program just errors out. no sneaky reads, no chaos, no cap. πŸ™ˆ

memory that Golf statements allocate? it's tracked and it gets freed at the end of the request. that's the whole system. πŸŽ€

and here's the part where you don't have to do anything: with Golf there is no need to free memory manually. memory gets automatically freed even if it's no longer accessible to the program, which is literally how memory leaks get prevented β€” and that matters so much for the stability of long-running processes. your little server that's been up for 400 days? still thriving. πŸ‘‘


πŸ¦‹ process-scoped memory πŸ¦‹

okay so some statements have a lil extra option β€” namely new-tree, new-hash, new-list, new-array and set-string β€” where you can allocate memory that won't get freed at the end of the request, and it stays available to any request served by the same process. this kind of memory is called "process-scoped". πŸ’«

and good news: a process-scoped string can be manually freed. so you're not stuck with it forever if you don't want to be. 🫢


πŸ’€ the dangling pointer situation πŸ’€

Golf handles memory references and assignments automatically, which prevents dangling memory. no manual bookkeeping, no "wait did I free that" 3am panic. not me being grateful for automatic reference handling fr fr. 😭

also, important detail: string results of any Golf statements will always create new memory, unless stated otherwise. so don't go assuming anything gets reused. it doesn't. πŸ’…


πŸŽ€ OPEN FILE DESCRIPTORS πŸŽ€

okay so this part is lowkey iconic for server girlies.

any files opened by the open-file statement are automatically closed by Golf at the end of the request. and here's why that slaps: it enhances the stability of long-running server processes, because Linux by default only offers a process about 1000 open files. πŸ“

a bug can quickly exhaust that pool and cause a malfunction or a crash β€” and Golf prevents this by closing any such open files when the request ends. so like. your file descriptor pool stays hydrated. πŸ’§βœ¨

not a drill bestie: ~1000 open files is the default Linux ceiling, and one leaky bug can eat the whole thing. Golf just closes them for you at request end. no notes. 🫢

🌈 SEE ALSO 🌈

  • Memory
  • memory-handling β€” See all documentation

and that's the page!! πŸŽ€ this version of the page is dated $DATE and belongs to version $VERSION β€” shoutout to whoever wrote it, love u, mwah πŸ’œ go forth and never call free() manually again, you don't have to, that's the whole point πŸ’…βœ¨

πŸ“¦ where this page comes from