Skip to main content

Featured

Game Development Tutorials In Android

Game Development Tutorials In Android Hi Guys,                 We are shortly started Game Development Tutorials in Android Studio. So everyone supports me and share this blogs to your friends. Guys, At this time everyone is freely available to source code and we are provide a video for step by step game developments. you are learn free and feel free to support us. Guys, if you have any question to me, so feel free to comment us. I will try to answer all the question as long as possible.                                                     Thank's                                                                          ...

Garbage Collector In Java

Garbage Collector In Java


In this Example, we will discuss an important chapter of Java, Garbage Collector but Before we can start to make the Garbage Collector Program, click on the Advertisements , available on this page.

/** Example shows garbage collector in action
    Note that the finalize() method of object GC1
    runs without being specifically called and that
    the id's of garbage collected objects are not
    always sequential.
*/

class TestGC {

    public static void main(String[] args) {
    
        Runtime rt = Runtime.getRuntime();
    
        System.out.println("Available Free Memory: " + rt.freeMemory());
        
        for(int i=0; i<10; i++ ) {
            GC1 x = new GC1(i);                        
        }

        System.out.println("Free Memory before call to gc():  " +                 
                rt.freeMemory());
        System.runFinalization();
        System.gc();
        System.out.println(" Free Memory after call to gc():  " +                 
                rt.freeMemory());                
        
    }
}

class GC1 {

    String str;
    int id;

    GC1(int i) {
        this.str = new String("abcdefghijklmnopqrstuvwxyz");        
        this.id = i;
    }
    
    protected void finalize() {
        System.out.println("GC1 object " + id + " has been finalized.");
    }
    

}

Compile and Run on this Program for Better Understanding this Program.

If this information is important to you , and you want to , I will continue writing some more details of Java, Android Programming Language, so click on the advertising, available on this page. This is motivate me for writing some more useful stuff, Thank's 

Comments