• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How does memory leaks happens in java?

 
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 ??
 
Author and all-around good cowpoke
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
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
 
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.

https://coderanch.com/t/468524/Performance/java/why-does-My-JSPs-are
 
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.
 
An elephant? An actual elephant. Into the apartment. How is the floor still here. Hold this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic