Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How does memory leaks happens in java?  RSS feed

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

Please let me know How does memory leaks happens in java ??

I mean there is a Garbage Collector that runs automatically , when ever memory is being filled up then why does memory leaks happens ??
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What Java programmers call "memory leaks" are typically due to not correctly disposing of all un-needed object references. The JVM thinks they may still be needed.

Bill
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can this be an example for it :


For example i have written a program that opens Database connections and Not closing Database connections means is it related to memory leak ??

Thanks in advance
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, not correctly disposing of special purpose objects such as DB connections or graphic contexts causes memory "leaks" and may also "leak" system resources such as file handles, DB connections, etc. - it is up to you the programmer to correctly handle these special objects.

It is more likely that you would run into mysterious failures but out of memory exceptions are also possible.

Bill
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In answer to another thread of yours (see below for link) I mentioned that the jamon jdbc driver will time your sql statements. It will also allow you to see how many connections you have open, and a number of other things such as how many SQL exceptions have been thrown. You can also view the stack traces via jamon.

http://www.coderanch.com/t/468524/Performance/java/why-does-My-JSPs-are
 
Dmitry Leskov
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravi Kiran V wrote:
Please let me know How does memory leaks happens in java ??

I mean there is a Garbage Collector that runs automatically , when ever memory is being filled up then why does memory leaks happens ??

The GC is not a silver bullet. It may only free an object if there are no links to it from other places, which can be local variables, static fields, other live objects, and even native code.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!