Senior
Mis on mälulek Java-s, isegi kui on prügikorjaja?
sobes.tech AI
Vastus AI-lt
Memory leak in Java is a situation where objects that are no longer needed by the application remain reachable from root references and are not removed by the garbage collector. Despite automatic garbage collection, if the program continues to hold references to unnecessary objects (for example, in collections, caches, or static fields), memory is not freed, leading to increased memory consumption and possible OutOfMemoryError.
Example: if objects are constantly added to a list but old ones are not removed, the list will grow, and memory will not be freed, even if the objects are no longer used in the program logic.