0

Just to understand the various ways in which memory leaks can happen in Java. Is it safe to say that the most general way is when a reference to an object is created and never released?

Ex :

DBManager db = new DBManager();
db.open();

and no call to :

db.close(); 
Mike Samuel
  • 118,113
  • 30
  • 216
  • 245
Arunabh Das
  • 13,212
  • 21
  • 86
  • 109
  • The most difficult part of the java that you don't know where the leak. – Roman C Apr 26 '14 at 20:58
  • 3
    This is rather a resource leak than a memory leak. There is a long thread here http://stackoverflow.com/questions/6470651/creating-a-memory-leak-with-java about the topic of Java memory leaks. – Harald Apr 26 '14 at 21:00
  • 1
    The situation you described is not a memory leak because you still can access `db`. – takendarkk Apr 26 '14 at 21:06
  • when your program terminates so will your database connection. it's sloppy to leave it open, but in a short-lives program it shouldn't cause too much issues. Get into a habit of building some sort of RuntimeManager class that you can call a `shutdown()` method on before exiting your program (and it will take care of closing all your resources, etc). – SnakeDoc Apr 26 '14 at 22:50

0 Answers0