• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Wierd spurt in used memory

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I recently wrote a small program that extensively uses Collections. And while I was profiling this for memory utilization on my local machine, I found something wierd happening. To measure memory util, I gave sysouts with totalMemory()-freeMemory() (invoked on the Runtime instance).



At the end of a run, I get the following statements on console:



There were 7 iterations of this loop in total.
Notice the output in bold.. The memory used upto this point was constant and then there's a sudden spurt of close to 80 Bytes. I have two questions..
1. Why is the memory usage constant over the first 4 iterations, till the section in bold? I mean, shouldnt there be a progressive increase if any?

2. Why the spurt?
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You would have to look a little deeper to see what is taking the memory. My bet would be this is typical behavior for collections. Both HashMaps and ArrayLists are initialized to hold some number of records (capacity) and only grow in memory usage when that capacity is reached (the rate and timing of growth for the ArrayList is left as implementation detail, while for HashMap you can control it with the load factor).

What you are seeing in the growth spurt is probably one or both of the collections you are using reaching its capacity and allocating more space for itself.
 
Deepak Narayan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank You!
 
Crusading Chameleon likes the size of this ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic