What are common mistakes developers make with memory leaks in Java?

Java, Memory Leaks, Developers, Common Mistakes, Resource Management, Memory Management
This article discusses common mistakes developers make with memory leaks in Java and how to avoid them.

    // Example of a memory leak due to a static reference
    import java.util.ArrayList;
    import java.util.List;

    public class MemoryLeakExample {
        private static List dataList = new ArrayList<>();

        public static void main(String[] args) {
            for (int i = 0; i < 100000; i++) {
                dataList.add("Item " + i);
            }
            // The dataList will keep growing, leading to a potential memory leak
        }
    }
    

Java Memory Leaks Developers Common Mistakes Resource Management Memory Management