Results 1 to 4 of 4
  1. #1
    Faisal Ahmed is offline Member
    Join Date
    Dec 2009
    Posts
    2
    Rep Power
    0

    Default Release Physical memory

    I am using Sigar dll for showing Physical memory...
    Java Code:
    class Memory()
    {
    ArrayList<HashMap> al=new ArrayList<HashMap>();
          public void EatMemory()
          {
              while(!Stop)
            {
                al.add(new HashMap());
                
              //Condition here
                //{
                  //  Stop=true;
                //}
            
             }
          }
    }
    and on button click event in the main form I create Memory object and call EatMemory() method
    Java Code:
    Memory mem=new Memory();
    mem.EatMemory();
    and also I have a timer run method which shows physical and virtual memory of the system every second.

    Java Code:
    Sigar s=new Sigar();
     Runtime r=Runtime.getRuntime();
     Mem m;
                public void run(){
                    try{
                        m=s.getMem();
                        long ActualUsed=m.getActualUsed()/1024;//in kilobytes
                        long ActualFree=m.getActualFree()/1024;//in kilobytes
                        long PhyTotal=m.getTotal()/1024;//in kilobytes
                        int perc=(int)m.getUsedPercent();
                        long VMTotal=r.totalMemory()/1024;
                        long VMFree=r.freeMemory()/1024;
                        long VMused=VMTotal-VMFree;
                        int vmperc=  (int)((new Double(VMused) / new Double(VMTotal))*100);
    
                        jlUsedMem.setText(String.valueOf(ActualUsed) );
                        jlFreeMem.setText(String.valueOf(ActualFree) );
                        jlTotalMem.setText(String.valueOf(PhyTotal) );
                        jlVMUsed.setText(String.valueOf(VMused));
                        jlVMFree.setText(String.valueOf(VMFree));
                        jlVMTotal.setText(String.valueOf(VMTotal));
                        jpbMemoryUsage.setValue(perc);
                        jpbaMemory.setValue(perc);
                        jpbVMMemoryUsage.setValue(vmperc);
                   }
                catch(Exception ex)
                {}
    }
    After EatMemory() method call Physical and Virtual memory increases and match the required condtion, when EatMemory() Method completes I call Runtime.getRuntime().gc() on another button event, after that Virtual Memory release memory but physical memory does not release memory. If I restart application then physical memory releases. How can it possible that like the way through which I release virtual memory, I am also release physical memory?

    Thanks.

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    I have no idea why you have written this strange program ....

    Anyway, the JVM does not guarantee you that it will release it's acquired free memory back to the OS so what you are observing is normal behavior.
    Last edited by r035198x; 03-24-2010 at 12:15 PM.

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,298
    Rep Power
    20

Similar Threads

  1. Creating Something physical
    By fresh83 in forum New To Java
    Replies: 17
    Last Post: 12-26-2009, 11:55 PM
  2. Replies: 2
    Last Post: 08-21-2008, 07:33 PM
  3. Replies: 1
    Last Post: 07-02-2008, 01:57 PM
  4. release info
    By venkatashiva in forum Java Software
    Replies: 3
    Last Post: 01-01-2008, 05:25 AM
  5. p-unit 0.10-release
    By levent in forum Java Software
    Replies: 0
    Last Post: 05-28-2007, 08:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •