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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Garbage Collection ....." Watch "Garbage Collection ....." New topic
Author

Garbage Collection .....

Muralidhar Gandepalli
Greenhorn

Joined: Apr 13, 2001
Posts: 13
Hi ,All
I have this question troubling me for some time ..."Inspite of having Garbage Collector in a VM can we have memory leaks ?.If yes can any one give one or two examples of these leaks "
Thanx in advance
Murali
Stefan Zoerner
Author
Ranch Hand

Joined: Nov 29, 2001
Posts: 121
Hello!
Yes, we can have Memory Leaks as in C or C++.
Condider the following program:

It causes an OutOfMemoryError in seconds. Of cause, this is not a real world example. But it shows, that just those objects are garbage collected, that are not in use. Not in use means, that there is no reference to it, i.e. it is not possibe to access the object any longer.
The many byte-arrays in my example still have references to them -- one each (the vector "knows" them). So the garbage collector can't decide to throw them away.
Programming errors can cause a similar effect. Of cause, that would not be that abvious. But forgetting to release references (e.g. by setting them to null) definetly can cause that situation. And at least one of these errors caused a memory leak in one of my projects ...
I hope that helps.
Greetings from Hamburg,
Stefan


Stefan Zoerner
Author of German LDAP-Book
Committer at Apache Directory Project
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Garbage Collection .....