4 ms·
>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 wo
by 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.