Comment puis-je créer une fuite de mémoire en Java

Mots clés : javamemorymemory-leaksjava

meilleur 2 Réponses Comment puis-je créer une fuite de mémoire en Java

vote vote

97

class MemorableClass {     static final ArrayList list = new ArrayList(100); } 
String str = readString(); // read lengthy string any source db,textbox/jsp etc.. // This will place the string in memory pool from which you can't remove str.intern(); 
try {     BufferedReader br = new BufferedReader(new FileReader(inputFile));     ...     ... } catch (Exception e) {     e.printStacktrace(); } 
try {     Connection conn = ConnectionFactory.getConnection();     ...     ... } catch (Exception e) {     e.printStacktrace(); } 
getServletContext().setAttribute("SOME_MAP", map); 
vote vote

82

class BadKey {    // no hashCode or equals();    public final String key;    public BadKey(String key) { this.key = key; } }  Map map = System.getProperties(); map.put(new BadKey("key"), "value"); // Memory leak even if your threads die. 

Questions similaires