3 ms·
Are you calling just allocating memory you’ll never use leaking? It is not. It is recoverable because for it not to be GC’d it has to be someone accessible. A m
by oivey 2y ago
Are you calling just allocating memory you’ll never use leaking? It is not. It is recoverable because for it not to be GC’d it has to be someone accessible. A memory leak means you lost the pointer to the memory, so now you can’t free it.
- gpderetta 2y ago> A memory leak means you lost the pointer to the memory, so now you can’t free it. that's an useless definition as otherwise it would be trivial to augment, say, malloc to prevent memory leaks. I would define a leak as unused memory that it is not otherwise reusable by a program.
- arccy 2y agolost can include you don't know where to find it even though you know it exists...
- Maxatar 2y ago>Are you calling just allocating memory you’ll never use leaking? It is not. Yes it is, by definition a memory leak is any memory that has been reserved but won't be read from or written to. If you allocate memory into a data structure and after some point in time you will never read from or write to that memory, then that memory constitutes a leak.
- cobbal 2y agoThere are (at least) 2 definitions of memory leak. The upsides of the definition you gave are that it's simple, well defined, and maximally precise (nothing that is safe to collect is considered live) The significant downside to this definition is that it's uncomputable. To know if memory is used requires knowing if a loop halts. The second definition of memory leak is "unreachability" which is a bit harder to nail down. It's a conservative approximation of the first definition, but is more popular because it's computable, and it's practical to write programs with or without GC that don't leak
- loeg 2y agoThe latter definition is not particularly useful for writing programs that run on hardware with finite memory. End users don't care whether or not the allocations are reachable when your program uses all the memory in the system and crowds out other programs, slows, and/or crashes.
- coding123 2y agoThat could also potentially be a cache in a highly unused program.
- jrockway 2y agoI'm OK with people using the expression "memory leak" to mean "unbounded growth in heap size over time". The case that I see most frequently is a routine that's set up like "use some memory, wait until an event that never happens happens, free memory". Technically if you let time run indefinitely, the memory would be freed. But since memory is finite, eventually you run out and your program crashes, which is annoying in this case.