• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

How does memory leaks happens in java?

 
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic