Runtime: freeMemory() : Runtime « java.lang « Java by API

Java by API
1. com.sun.image.codec.jpeg
2. java.applet
3. java.awt
4. java.awt.datatransfer
5. java.awt.dnd
6. java.awt.event
7. java.awt.font
8. java.awt.geom
9. java.awt.image
10. java.awt.print
11. java.beans
12. java.io
13. java.lang
14. java.lang.instrument
15. java.lang.management
16. java.lang.reflect
17. java.math
18. java.net
19. java.nio
20. java.nio.channels
21. java.nio.charset
22. java.rmi.server
23. java.security
24. java.security.cert
25. java.sql
26. java.text
27. java.util
28. java.util.concurrent
29. java.util.logging
30. java.util.prefs
31. java.util.regex
32. java.util.zip
33. javax.accessibility
34. javax.comm
35. javax.naming
36. javax.net
37. javax.net.ssl
38. javax.print
39. javax.servlet
40. javax.servlet.http
41. javax.sql
42. javax.sql.rowset
43. javax.swing
44. javax.swing.border
45. javax.swing.colorchooser
46. javax.swing.event
47. javax.swing.filechooser
48. javax.swing.plaf.basic
49. javax.swing.plaf.metal
50. javax.swing.plaf.synth
51. javax.swing.table
52. javax.swing.text
53. javax.swing.text.html
54. javax.swing.text.html.parser
55. javax.swing.tree
56. javax.swing.undo
57. javax.xml
58. javax.xml.parsers
59. javax.xml.transform
60. javax.xml.transform.dom
61. javax.xml.transform.stream
62. javax.xml.validation
63. javax.xml.xpath
64. org.apache.commons.lang
65. org.apache.commons.lang.builder
66. org.apache.commons.lang.exception
67. org.apache.commons.lang.time
68. org.apache.commons.logging
69. org.apache.commons.math
70. org.eclipse.jface.action
71. org.eclipse.jface.dialogs
72. org.eclipse.jface.operation
73. org.eclipse.jface.viewers
74. org.eclipse.jface.window
75. org.eclipse.jface.wizard
76. org.eclipse.swt
77. org.eclipse.swt.browser
78. org.eclipse.swt.custom
79. org.eclipse.swt.dnd
80. org.eclipse.swt.events
81. org.eclipse.swt.graphics
82. org.eclipse.swt.layout
83. org.eclipse.swt.ole.win32
84. org.eclipse.swt.printing
85. org.eclipse.swt.program
86. org.eclipse.swt.widgets
87. org.w3c.dom
88. org.xml.sax
89. org.xml.sax.helpers
90. sun.audio
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java by API » java.lang » Runtime 
Runtime: freeMemory()

/*
 * Output: 
Total memory is: 2031616
Initial free memory: 1774312
Free memory after garbage collection: 1875680
Free memory after allocation: 1715296
Memory used by allocation: 160384
Free memory after collecting discarded Integers: 1875680
 */

public class MainClass {
  public static void main(String args[]) {
    Runtime r = Runtime.getRuntime();
    long mem1, mem2;
    Integer someints[] new Integer[10000];

    System.out.println("Total memory is: " + r.totalMemory());

    mem1 = r.freeMemory();
    System.out.println("Initial free memory: " + mem1);
    r.gc();
    mem1 = r.freeMemory();
    System.out.println("Free memory after garbage collection: " + mem1);

    for (int i = 0; i < someints.length; i++)
      someints[inew Integer(i)// allocate integers

    mem2 = r.freeMemory();
    System.out.println("Free memory after allocation: " + mem2);
    System.out.println("Memory used by allocation: " (mem1 - mem2));

    for (int i = 0; i < someints.length; i++)
      someints[inull;

    r.gc()// request garbage collection

    mem2 = r.freeMemory();
    System.out.println("Free memory after collecting" " discarded Integers: "
        + mem2);

  }
}
           
       
Related examples in the same category
1. Runtime: exec(String[] command)
2. Runtime: exec(String command) (2)
3. Runtime: gc()
4. Runtime.getRuntime()
5. Runtime: addShutdownHook(Thread hook)
6. Runtime: totalMemory()
w_w__w._jav__a2___s.__c___om___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.