answersLogoWhite

0


Best Answer

Garbage collection is an automatic memory management feature built into the JVM. During the course of program execution, it will find objects that are no longer being used and allow their memory allocations to be used in other parts of the program.

As mentioned, the process is automatic. That means you don't have to worry about that part of your program. It is not a class or an object - just a part of the VM that runs "under the hood" as your program is executed.

However, garbage collection runs periodically so as to be more efficient. If you want to call the garbage collector at a particular moment, the Runtime class allows access to the garbage collector. To invoke, call the following: Runtime.getRuntime().gc().

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: In java garbage collection is a class or an object or anything else?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How can you differentiate a class from an object of a class?

A class is a collection of similar objects while an object is the individual instance of a class.


Can you force a garbage collecter to run for the specific class?

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). It is essential that you understand this concept for the exam. The garbage collection routines that Java provides are members of the Runtime class. The Runtime class is a special class that has a single object (a Singleton) for each main program. The Runtime object provides a mechanism for communicating directly with the virtual machine. To get the Runtime instance, you can use the method Runtime.getRuntime(), which returns the Singleton. Once you have the Singleton you can invoke the garbage collector using the gc() method. Alternatively, you can call the same method on the System class, which has static methods that can do the work of obtaining the Singleton for you. The simplest way to ask for garbage collection (remember-just a request) is System.gc(); Theoretically, after calling System.gc(), you will have as much free memory as possible. We say theoretically because this routine does not always work that way. First, your JVM may not have implemented this routine; the language specification allows this routine to do nothing at all. Second, another thread might grab lots of memory right after you run the garbage collector. This is not to say that System.gc() is a useless method-it's much better than nothing. You just can't rely on System.gc() to free up enough memory so that you don't have to worry about running out of memory


How can you force the garbage collector to run?

You can't force it but you call System.gc(), which is a "hint" to the runtime engine that now might be a good time to run the GC. But garbage collection using this method is not guaranteed to be done immediately. there is another way to explicitly call the gc(). this method is also define in Runtime class of package java.lang. But u can not create a direct object of class Runtime like Runtime a = new Runtime(); //wrong For that u have to call the method getRuntime() which is static and it is also define in Runtime class the way to create object is Runtime run; //right run = Runtime.getRuntime(); //right now u can call the gc() through the "run " Object. like run.gc(); //right


What are objects and how are they created from a class in Java?

Literally, an object in programming is a collection of data and functions (remember that functions just bits of data, too). An object's class defines what those data and functions are and how to make new objects of that class. So a class is like a cast to make a plastic toy and an object is like a single plastic toy itself.


What is Implicit garbage collection in java?

It returns memory to the memory pool by destroying objects that no longer have a reference to them.Memory management is a crucial element in many types of applications. Consider a program that reads in large amounts of data, say from somewhere else on a network, and then writes that data into a database on a hard drive. A typical design would be to read the data into some sort of collection in memory, perform some operations on the data, and then write the data into the database. After the data is written into the database, the collection that stored the data temporarily must be emptied of old data or deleted and recreated before processing the next batch. This operation might be performed thousands of times, and in languages like C or C++ that do not offer automatic garbage collection, a small flaw in the logic that manually empties or deletes the collection data structures can allow small amounts of memory to be improperly reclaimed or lost forever. These small losses are called memory leaks, and over many thousands of iterations they can make enough memory inaccessible that programs will eventually crash. Creating code that performs manual memory management cleanly and thoroughly is a complex task.Java's garbage collector provides an automatic solution to memory management. In most cases it frees you from having to add any memory management logic to your application. The downside to automatic garbage collection is that you can't completely control when it runs and when it doesn't.Overview of Java's Garbage CollectorGarbage collection is the phrase used to describe automatic memory management in Java. Whenever a software program executes (in any programming language for that matter), it uses memory in several different ways. We're not going to get into Computer Science 101 here, but it's typical for memory to be used to create a stack, a heap, in Java's case constant pools, and method areas. The heap is that part of memory where Java objects live, and it's the one and only part of memory that is in any way involved in the garbage collection process.So, all of garbage collection revolves around making sure that the heap has as much free space as possible. For the purpose of the exam, what this boils down to is deleting any objects that are no longer reachable by the Java program running. When the garbage collector runs, its purpose is to find and delete objects that cannot be reached. If you think of a Java program as being in a constant cycle of creating the objects it needs (which occupy space on the heap), and then discarding them when they're no longer needed, creating new objects, discarding them, and so on, the missing piece of the puzzle is the garbage collector. When it runs, it looks for those discarded objects and deletes them from memory so that the cycle of using memory and releasing it can continue.


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.


Every class in derives from what class?

From the Object class.From the Object class.From the Object class.From the Object class.


What is class in DBMS?

class in dbms is nothing but a collection of attributes.... class in java is defined as collection of objects....:D


What do you mean by MFC Collection Classes in visual programming?

MFC provides a number of ready-to-use arrays, lists, and maps that are referred to as collection classes. Using a collection allows the programmer to hold, process, or store groups of class objects or variables of certain standard types. You can use these collection classes to store objects in memory, and for some standard types they provide serialization support also. The collection varies in size to accommodate as many objects as memory constraints will allow. A collection object appears as a single object. Class member functions can operate on all elements of the collection. A collection class is characterized by its shape and by the types of its elements. The shape refers to the way the objects are organized and stored by the collection. MFC provides three basic collection shapes: arrays, lists, and maps (also known as dictionaries).


What is class and objects?

class is template of object and object is instance of a class


What is object class in java?

object class is a super class for all other class...


What is the Object class parent?

Object is the topmost class in the Java Class hierarchy. There is no Class above Object. All classes in Java are implicitly derived from Object.