9 ms·
You can also define a memory leak as retaining memory outside of the scope its needed. The program lifespan is one of those scopes, but there are also smaller s
by rovolo 5y ago
You can also define a memory leak as retaining memory outside of the scope its needed. The program lifespan is one of those scopes, but there are also smaller scopes you can leak memory to. An example is the per-request scope on a server.
> Otherwise you're just using memory leak to mean "My objects live longer than I thought", which is an issue probably affecting more than 99% of existing programs.
Yes, it's a class of errors. Big programs always have errors, so it's not necessarily helpful to say "this program has a null-pointer error" or "this program has a memory leak". The scope of the problem depends on the impact caused by the error.
For example, a memory leak during a computation could still bring down your program. Imagine a file uploader which does an md5 computation of a file before uploading the file. If the uploader pulls the entire file into memory for checksumming when it didn't intend to, a large file could cause an OOM error and crash your program. That is a memory leak even though it is scoped to the md5 operation and not the program lifetime.