• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

I tried a lot but unable to find the reason for this .....  RSS feed

 
Ranch Hand
Posts: 257
Firefox Browser Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the following code and see the output, I tried to figure out and searched on net to get the reason for this behavior but I did not get any right clue for that ....

Can any one give the right clue, and let me try more based on that clue,




OUTPUT:
--------------

Before 174032

After 107704
[ September 20, 2006: Message edited by: Srinivas Kalvala ]
 
Ranch Hand
Posts: 1166
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you change the code so that it calculates and prints out the amount of memory used inside the loop after the gc() call, do the results make sense?
[ September 20, 2006: Message edited by: Ryan McGuire ]
 
Srinivas Kalvala
Ranch Hand
Posts: 257
Firefox Browser Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I did not get you Ryan.
 
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(Not an Advanced question)

What's this code supposed to show?

I suppose totalMemory() minus freeMemory() will give approximately the amount of memory in use by objects on the heap. When a full GC runs, all objects on the heap that are no longer referenced get freed. That will mean freeMemory() increases, so the difference reduces, like you saw.

Note first that calling gc() doesn't guarantee to do a full GC, or indeed anything, even if you call it hundreds of times (what's the idea of that anyway?). Second, note that, depending on JVM settings, the totalMemory() may change, as the JVM adapts the heap size to the program's requirements.
[ September 21, 2006: Message edited by: Peter Chase ]
 
author and iconoclast
Posts: 24203
43
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed. And never forget that a JVM, even one running a very simple user program like this, is a multithreaded process. Other stuff is going on in the background, and that other stuff may very well be allocating (and disposing) memory.
 
You don't like waffles? Well, do you like this tiny ad?
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!