GOLF(2gg)

πŸ“¦ version 601.4.41, in ubuntu questing

πŸ’– GOLF(2gg) β€” delete-string πŸ’–

okay so bestie, we're in the Golf manual, section 2gg, and today's main character is delete-string. yes she's from Development, and yes she eats. let's get into it ✨


🌸 NAME 🌸

delete-string β€” (strings) πŸŽ€

πŸ¦‹ PURPOSE πŸ¦‹

Free string memory. that's it, that's the job, she's a memory liberator πŸ’…

✨ SYNTAX ✨

delete-string <string>

πŸ’œ DESCRIPTION πŸ’œ

delete-string frees the <string> variable that was previously allocated by a Golf statement. freeing your girl, setting her free, the whole vibe πŸ•ŠοΈ

ngl though β€” freeing memory is in most cases unnecessary, because Golf will automatically do it for you at the end of each request. so if you're reaching for delete-string, you should have a good reason, fr fr. otherwise it's giving "doing extra homework for no reason" 😭

here's the tea on how Golf actually tracks this: Golf keeps count of <string> references for process-scoped memory (go peek at memory-handling for that whole situation). and that kind of memory gets deleted at the end of the request, once the reference count reaches zero. slay, automatic cleanup, we love to see it πŸ‘‘

now for non-process-scoped memory, it's a lil different. if <string> is referenced by other variables, then <string> may not be deleted. she's held, she's claimed, she's not going anywhere. but β€” and this is the important part β€” regardless of whether the memory referenced by <string> is actually deleted or not, <string> becomes an empty string ("") after delete-string. so the variable itself is always emptied out, no cap. periodt πŸ’€

⚠️ heads up bestie: don't just sprinkle delete-string around for fun. Golf handles it for you at the end of each request, so only call it when you've got a real reason. otherwise you're just doing cardio for nothing πŸƒβ™€οΈ

πŸ“ EXAMPLES πŸ“

Allocate and free a random string β€” look how cute this is:

random-string to ran_str
...
delete-string ran_str

Free a string allocated by write-string (this one's made of 100 "Hello World"s, obsessed):

write-string ws
    start-loop repeat 100
        @Hello World
    end-loop
end-write-string
...
delete-string ws

🌈 SEE ALSO 🌈

Strings

concatenate-strings copy-string count-substring delete-string lower-string new-string read-split replace-string set-string split-string string-length trim-string upper-string write-string β€” See all documentation ✨


and that's the whole page, bestie 🫢 go free some strings (responsibly, or honestly just let Golf do it). this was $VERSION, dated $DATE, and yes this is still GOLF(2gg) β€” mwah πŸ’–πŸ§šβ­

πŸ“¦ where this page comes from