Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What is garbage collection in Java, and how can it be used ?

Answer Posted / faiz misbah iiit-bangalore

Each time an object is created in java,it goes into an area
of memory known as the HEAP.All objects-no matter when.
where or how they're created -live on the heap.But it's not
just old memory heap;the java heap is actually called the
Garbage-collectible Heap.When you create an object, java
allocates memory space on the heap according to how much
that particular object needs.java manage that memory for
you!When the JVM can 'see' that an object can never be used
again,that object become eligible for garbage collection.and
if you're running low on memory,the garbage collector will
run,throw out the unreachable objects,and free up the
space.so that the space can be reused.

Run object finalization using System class

public class Main {

public static void main(String[] args) {
System.runFinalization();
}
}
Run the garbage collector using System class

public class Main {

public static void main(String[] args) {

System.gc();

}

}

The Lifetime of an Object

class Sphere {
double radius; // Radius of a sphere

Sphere() {

}

// Class constructor
Sphere(double theRadius) {
radius = theRadius; // Set the radius

}
}

public class MainClass {
public static void main(String[] arg){
Sphere sp = new Sphere();

System.gc();
}

}

Is This Answer Correct ?    13 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain what do you mean by functional overloading in java?

951


Why bytecode is called bytecode?

1092


how we can create packages in java?

908


How to access arraylist elements in java?

940


What's a method in programming?

990


Explain parallel processing in java8?

1154


What is data type example?

900


How many bits is a string?

939


Why do we use return statement?

966


what is optional in java 8?

1009


what is ststic with example

2002


What is a final class ?

1079


What are the principle concepts of oops?

906


Can a abstract class be declared final?

944


What are the 5 types of research methods?

1084