Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Memory Leaks

 
Neil Andrade
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does Java have memory leaks or does C/C++ have meory leaks ???
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Geoff Griffiths
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
ken chou
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 527
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah null will definitely solve the memory leak problem.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic