Does Java have memory leaks or does C/C++ have meory leaks ???
Joined: Jan 07, 1999
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.
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.
Joined: Feb 08, 2001
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).]
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.
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?
Joined: Oct 31, 2000
yeah null will definitely solve the memory leak problem.