aspose file tools*
The moose likes Java in General and the fly likes Memory Leaks Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Memory Leaks" Watch "Memory Leaks" New topic
Author

Memory Leaks

Neil Andrade
Greenhorn

Joined: Mar 08, 2001
Posts: 12
Does Java have memory leaks or does C/C++ have meory leaks ???
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Yes.
Java can have "memory leaks" if objects are left referenced by other objects still in use, when they should have been released for Garbage Collection. C++ has no Garbage Collection and can have "memory leaks" whenever a programmer doesn't exactly match up memory allocation and memory release.
On sensible operating systems, these effects will only last until a particular program terminates, but on DOS, for example, some memory leaks can still consume memory until the machine is rebooted.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Geoff Griffiths
Greenhorn

Joined: Mar 18, 2001
Posts: 17
memroy leakage can occur in Java but most is prevented by Java's garbadge collection. C++ it is totally up to the programmer to do the garbadge collection.
ken chou
Ranch Hand

Joined: Feb 08, 2001
Posts: 68
Does the Java Programmer doesn't need to care about the garbadge collection at all since it will be taken care automatically? If not, how do we know when to take the action to prevent the memory leak whenever the automatic garbadge collection wouldn't be able to prevent the memory leak?
[This message has been edited by ken chou (edited March 20, 2001).]
Hema Menon
Ranch Hand

Joined: Oct 29, 2000
Posts: 569
Here's the link from IBM Developerworks, to an interesting article on how to prevent memory leaks in Java.
http://www-106.ibm.com/developerworks/library/j-leaks/index.html
Thanks,
hm


~hm
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
Does the Java Programmer doesn't need to care about the garbadge collection at all since it will be taken care automatically?
Garbage collection only releases the memory consumed by
objects which donot have references to them. The releasing
part is automatic. However, not having references is still
in the programmers hands.
If not, how do we know when to take the action to prevent the memory leak whenever the automatic garbadge collection wouldn't
be able to prevent the memory leak?

Stating the above stmt in different words, "Automatic garbage
collection wouldn't work when the object (supposed to be
garbage collected) has references."
Use the above link and read more. The article uses a
profiler JProbe to explain the concept.
Thanks for the article Menon.

regds.
- satya

Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
ken chou
Ranch Hand

Joined: Feb 08, 2001
Posts: 68

So in Java if we set all the references to unused Object
to "null" proporly. It will be guaranteed that memory leak
wouldn't happen since that's the only reason that could cause
memory leak problem in Java, right?
Anil Vupputuri
Ranch Hand

Joined: Oct 31, 2000
Posts: 527
yeah null will definitely solve the memory leak problem.


SCJP 1.5, SCEA, ICED (287,484,486)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Memory Leaks
 
Similar Threads
Memory leaks
Use of Java
memory leaks
How does memory leaks happens in java?
Memory management