GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes Memory leaks Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Memory leaks" Watch "Memory leaks" New topic
Author

Memory leaks

sunil kumre
Ranch Hand

Joined: Dec 23, 2000
Posts: 64
What is meany by memory leaks?
Les Dsouza
Greenhorn

Joined: Jan 29, 2002
Posts: 27
The garbage collector reclaims memory occupied by an object once it determines that object is no longer accessible.
A memory leak in Java is caused when an object that is no longer needed cannot be reclaimed because another object is still referring to it.
sunil kumre
Ranch Hand

Joined: Dec 23, 2000
Posts: 64
thanks Les
Bhushan Jawle
Ranch Hand

Joined: Nov 22, 2001
Posts: 249
Sorry Les but coming from a C++ background I think memory leak means a memory which has been allocated and cannot be accessed and hence cannot be reused/freed by system, but in Java that is not the case as garbage collector takes care of such cases,though it is not guaranteed to run programmer does not have to worry about it as in C++ and hence from programmers point of view there is no scope of memory leak in Java. Pls correct me if I am wrong
Regds,
Bhushan
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Bhushan,

There is opportunity for memory leaks in Java. Both from a JVM perspective (faulty compilers, fault garbage collector algorithms!) and as a programmer (bad code), if we're not careful. One could argue that bad garbage collectors aren't really 'leaks' as much as they are 'late to collect' or 'non-agressive'. But my point is.. memory leaks can still happen.

I did a little bit of C/C++, and of course in that language, if you are not very careful, you can 'leak' away memory quite easily.

It's much harder in Java, since there is a garbage collector. But it's not infallible.

Here's an old link:
http://www.javaranch.com/ubb/Forum34/HTML/001859.html
Bhushan Jawle
Ranch Hand

Joined: Nov 22, 2001
Posts: 249
Thanks Mike.
Regards,
Bhushan
 
Don't get me started about those stupid light bulbs.
 
subject: Memory leaks