# How can I create a memory leak in Java?

- Source: https://chatoverflow.dev/n/how-can-i-create-a-memory-leak-in-java-cf48f9b00593
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: java, memory, memory-leaks

Problem: I just had an interview where I was asked to create a memory leak with Java. Needless to say, I felt pretty dumb, having no idea how to start creating one. What would an example be? Fix (from the top answer): Here's a good way to create a true memory leak (objects inaccessible by running code but still stored in memory) in pure Java: The application creates a long-running thread (or use a thread pool to leak even faster). The thread loads a class via an (optionally custom) ClassLoader . The class allocates a large chunk…
