Live data from Hacker News

Memory leak proof every C program

flak.tedunangst.com

171–175 of 175 posts

Re: Memory leak proof every C program

#171

Earlier quoted context omitted.

Yes. Hence the word 'joke' I used. For short running programs, it's fine. The longer running programs you can often find a few places where 95% of the leaks happen and easily 'free' those leaving the last 5% to leak slowly. It depends. Just remember it's a valid solution sometimes.

I still don't understand. The joke and the sometimes valid solution are different strategies . The joke only reminds people of the valid solution. It feels like multiple people are giving the article the briefest skim and assuming the two are the same. Perhaps focusing on the words "optional to call free" and extrapolating off that without looking at the code or properly reading the rest of the text. Unless I'm badly…

I think you're just looking more deeply at it than I am. No more than that.

Re: Memory leak proof every C program

#172

Earlier quoted context omitted.

Yeah, I first came across this strategy as a performance optimization in something Jared Sumner wrote about Bun (which is written in Zig).

Link to devblog article/tweet?

Can't find it now, sorry. Can't remember if it was in a tweet or if it was an offhand comment in Bun documentation somewhere.

Re: Memory leak proof every C program

#173

Earlier quoted context omitted.

This is like going back to malloc and free but using array indices rather than pointers, and each type has a fixed-size heap. We did it in one Microsoft service because the very first .NET releases had slow GCs.

One could argue that pointers are just array indices, where the array is your whole address space, and you only get the one array for all your types.

It helps that pointer-to-T is a distinct type, where (apart from Ada) index-into-array-of-T is just like any other integer.

Re: Memory leak proof every C program

#174

Earlier quoted context omitted.

it's not funny, it's not obvious and it's wasting a lot of people's time. ha. ha. ha.

Its painfully obvious.

you haven't had to fix bugs in other people's code enough, this could be an actual piece of code, which makes it not distinguishable as a joke

Re: Memory leak proof every C program

#175
post #160

Earlier quoted context omitted.

it's not funny, it's not obvious and it's wasting a lot of people's time. ha. ha. ha.

It's quite obvious... "If you don’t call free, memory usage will increase over time, but technically, it’s not a leak."

there is plenty of code that is designed not to free at all because the program will not run long enough to generate much garbage. and having the whole process shut down is simpler than unwinding everything perfectly. so, no, it's not obvious. I had no trouble reading what the code did (and didn't) but it's not obvious that the author understood it. There are plenty of people here who need that much help with C
Post reply on HN