• 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Determine how many mbytes are GC Android

Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have this code below which makes 300 http requests and each request returns 10000 rows from database. Total size of 10000 is approximately 0.4mb. So 300*0.4  = 120mb. I want to check the total Heap size whether it surpasses a certain  threshold lets say 256mb. If it does, then the app terminates. But sometimes depending the android version jvm doesnt call gc in time so it reaches 256mb but the 100mb might be garbage collectable and the app would terminate.

Is there a way to determine how many mbytes going to be freed?
Thank you

Posts: 1868
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Java there is not way to force garbage collection and there is also no way to determine how much memory would be freed if garbage collection occurs.
You can ask Java to run garbage collection by running System.gc() but that request may be ignored.
Given that you cannot enforce garbage collection using Java, you cannot know how much memory will be freed up when garbage collection happens.

But we are talking about Android and an alternative to using Java for Android programming is to use C or C++.
I do not know C or C++ enough to know how this is implemented in general or how it's implemented in Android.
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic