Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Does Garbage Collection ensure me more memory ?

843789Oct 9 2009 — edited Oct 13 2009
This is a question i saw in a mock exam.


You are concerned about that your program may attempt to use more memory than is
available. To avoid this situation you want to ensure that the Java Virtual Machine will
run its garbage collection just before you start a complex routine. What can you do to
be certain that garbage collection will run when you want.
(1) You cannot be certain when garbage collection will run
(2) Use the Runtime.gc() method to force garbage collection
(3) Ensure that all the variables you require to be garbage collected are set to null
(4) Use the System.gc() method to force garbage collection


Now,as far as my little knowledge in java,GC manages the available memory and doesnot CREATE more memory for my program to run.So what is the highlighted part trying to suggest ?

1. Also is my assumption correct ?
2. How do i know how much memory is allocated in my machine for my JVM ?
3. Is memory space in JVM and the heap space in memory for the objects one and the same ?


I hope my questions make sense,and i am just too confused reading various terminologies on memory management.

Thank you for your consideration.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 10 2009
Added on Oct 9 2009
23 comments
289 views