Results 1 to 5 of 5
  1. #1
    jsobel is offline Member
    Join Date
    Apr 2012
    Posts
    68
    Rep Power
    0

    Default Checking memory usage

    will these methods work to get me my memory usage for a program in megabytes they dont seem to work
    Java Code:
    	public String CurrentMemory()
    	{
                   double currentMemory=((double)((double)(Runtime.getRuntime().totalMemory()/1024)/1024))- ((double)((double)(Runtime.getRuntime().freeMemory()/1024)/1024)); 
    	return String.valueOf(currentMemory);
    	}
    	public String AvailableMemory()
    	{
    	double availableMemory = ((double)((double)(Runtime.getRuntime().freeMemory()/1024)/1024)); 
    	return String.valueOf(availableMemory);
    	}
    	public String AllocatedMemory()
    	{
    	double allocatedMemory = ((double)((double)(Runtime.getRuntime().maxMemory()/1024)/1024)); 
    	return String.valueOf(allocatedMemory);
    	}

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,931
    Rep Power
    19

    Default Re: Checking memory usage

    Why don't you do the calculation first (total - free) and then convert?

    Anyway, in what way do they not work?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    javin.paul is offline Member
    Join Date
    Oct 2011
    Posts
    35
    Rep Power
    0

    Default Re: Checking memory usage

    Method should work, what is the problem you are getting ? Another thing use long , why are you using double ? long seems better choice to me as all those Runtime method return long.

  4. #4
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,931
    Rep Power
    19

    Default Re: Checking memory usage

    Quote Originally Posted by javin.paul View Post
    Method should work, what is the problem you are getting ? Another thing use long , why are you using double ? long seems better choice to me as all those Runtime method return long.
    They're using double because of the calculation, and presumably want the fractions?
    I don't understand why.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    javin.paul is offline Member
    Join Date
    Oct 2011
    Posts
    35
    Rep Power
    0

    Default Re: Checking memory usage

    Me too. Even though I think only one cast is required because then rest of calculation automatically becomes double, isn't it ?

Similar Threads

  1. Application Memory Usage...
    By switch in forum AWT / Swing
    Replies: 1
    Last Post: 01-26-2012, 07:13 PM
  2. Isolating memory usage
    By bmelloni in forum Advanced Java
    Replies: 0
    Last Post: 09-13-2011, 08:47 PM
  3. Lowering Memory usage
    By CuddlyKittens11 in forum Advanced Java
    Replies: 6
    Last Post: 04-27-2011, 07:53 PM
  4. Memory usage
    By Moon_E in forum New To Java
    Replies: 20
    Last Post: 07-09-2010, 10:53 PM
  5. JVM memory usage
    By lardum in forum New To Java
    Replies: 7
    Last Post: 06-26-2008, 03:30 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
  •