answersLogoWhite

0


Best Answer

No one can force garbage collector to free memory, A java object is subjected to garbage collection when it can not be reached by the program in which it is being used. Programmer can request for garbage collection by System.gc() but JVM doesn't guarantee that is will start immediately

Actually, the specific method for GC and how it will be run is dependent on the JVM implementation being used.

For instance, Sun (now Oracle)'s Hotspot JVM has several different GC designs, one of which (the RealTime engine) can be immediately triggered via a System.gc() call. Each type of GC will have different triggers and thresholds as to when it will be run, which allows the user to pick the GC option that they think will be least disruptive and most effective for their particular application.

You must read the JVM documentation for your particular VM to see what available GC options there are, how each GC method works, and what the various thresholds are.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

Garbage collection in Java is the process of cleaning up the heap. When a Java program releases a storage area in the heap, the space is simply marked as available but can't be reused as Java only allocates memory from the top of the heap. Every so often, or when there is no memory available on the heap for a new 'get' request, garbage Collection is invoked to rearrange the heap to eliminate the holes (where memory was released). In effect all of the used memory is pushed down to the bottom of the heap leaving a large chuck of memory at the top for new memory requests.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: When does Garbage collection occur in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

2 What is the purpose of garbage collection in java and when is it used?

Garbage collection prevents memory leaks. In Java, the Java Virtual Machine will garbage collect whenever there is memory that has no references.


What is memory leak problemin java?

Memory leaks do not occur in Java as the garbage collector clears the memory which has no references.


What is the difference between garbage collector and finalization?

When all references to an object is Java are gone, the garbage collector will come along and free up the memory used by that object.Every Java object has a method named finalize, which is called by the garbage collector when the memory for that object is being deallocated. "Finalization" is just a name given to the act of calling the finalize method during garbage collection.


How do you write a Program on garbage collector in java?

Garbage collection is an operation that happens automatically in Java. We cannot write programs to perform them. All we can do is call the system's implementation of the Garbage collector and hope that it would execute. "Runtime.gc();" Place the above piece of code in your code, if you want to invoke the garbage collector. Invoking the runtime's implementation of the gc does not guarantee the execution of the garbage collector. It may or may not run. The JVM decides on that.


Why java does not support destructor?

AMIT KUMAR3th Nov , 2014Java does not support destructors, since java supports the concept of garbage collection,hence the garbage collector is used to automatically free the space which has occupied by the program while running.Garbage collector calls the finalize() method which is defined in the object class. finalize() method is called once for each object.

Related questions

2 What is the purpose of garbage collection in java and when is it used?

Garbage collection prevents memory leaks. In Java, the Java Virtual Machine will garbage collect whenever there is memory that has no references.


Garbagecolllecter in java?

Yes, Java programming language has a Garbage collector for unused memory. and the best part about it is that it does it automatically. The Garbage Collector is built into the Java Virtual Machine, and will do automatic garbage collection for you. If you chose to compile your Java code down to native code (via a Java->native code compiler), then NO garbage collection is done for you.


How do you force garbage collection in java?

. Garbage collection cannot be forced. Calling System.gc() or Runtime.gc() is not 100 percent reliable, since the garbage-collection thread might defer to a thread of higher priority


What is memory leak problemin java?

Memory leaks do not occur in Java as the garbage collector clears the memory which has no references.


On what days does garbage collection typically occur?

garbage collection can typically occur when ever. it all just depends on the state or city you're in. it mostly occurs on Thursdays,Mondays,Tuesdays,and even Fridays.


How you can inforce the garbage collection?

Forcing Garbage CollectionFirst and foremost, unlike this paragraphs title, garbage collection cannot be forced. However, Java provides some methods that allow you to request that the JVM perform garbage collection.In reality, it is possible only to suggest to the JVM that it perform garbage collection. However, there are no guarantees the JVM will actually remove all of the unused objects from memory (even if garbage collection is run).


What is the garbage collection in java?

The garbage collector is a process that will search for unreachable objects - objects which can't be reached from the main program - and destroy them, thus reclaiming the space they use.


Why is your computer temporarily freezing when you play games run on java?

It may be loading something. Also, Java technology uses something called "garbage collection", which may temporarily freeze the game - or whatever program you are running. Garbage collection is a process used to reclaim memory that was once assigned to some aspect of a program, but that is no longer used.


What is the difference between garbage collector and finalization?

When all references to an object is Java are gone, the garbage collector will come along and free up the memory used by that object.Every Java object has a method named finalize, which is called by the garbage collector when the memory for that object is being deallocated. "Finalization" is just a name given to the act of calling the finalize method during garbage collection.


How do you write a Program on garbage collector in java?

Garbage collection is an operation that happens automatically in Java. We cannot write programs to perform them. All we can do is call the system's implementation of the Garbage collector and hope that it would execute. "Runtime.gc();" Place the above piece of code in your code, if you want to invoke the garbage collector. Invoking the runtime's implementation of the gc does not guarantee the execution of the garbage collector. It may or may not run. The JVM decides on that.


How garbage collector works on anonymous class in java?

about the garbage collector it is in java and it is mainly responsible for dynamic memory manegement


Why java does not support destructor?

AMIT KUMAR3th Nov , 2014Java does not support destructors, since java supports the concept of garbage collection,hence the garbage collector is used to automatically free the space which has occupied by the program while running.Garbage collector calls the finalize() method which is defined in the object class. finalize() method is called once for each object.