wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes a question on Runtime.getRuntime().totalMemory() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "a question on Runtime.getRuntime().totalMemory()" Watch "a question on Runtime.getRuntime().totalMemory()" New topic

a question on Runtime.getRuntime().totalMemory()

cake naiyou

Joined: Apr 29, 2011
Posts: 27
The following function is used to compute memory usage.

I do not understand how to understand "Runtime.getRuntime().totalMemory()"? In specific, how to understand the relationships connecting "Runtime", "getRuntime()" and "totalMemory()"?
Rob Spoor

Joined: Oct 27, 2005
Posts: 19649

Runtime is an abstract class. There is no direct way to instantiate it. It has a static method to get an instance of some unknown subclass. This method is called getRuntime(). Therefore, Runtime.getRuntime() returns an instance of a subclass of Runtime.
totalMemory() is an instance method that you call on that instance. Your single line is similar to this:

How To Ask Questions How To Answer Questions
It is sorta covered in the JavaRanch Style Guide.
subject: a question on Runtime.getRuntime().totalMemory()
Similar Threads
Memory leak
Increase memory for tomcat
garbage collection
How to find out how much memory machine has.
Optimization Java Code - performance Vs memory