Win a copy of Java Persistence with Spring Data and Hibernate this week in the Spring forum!
  • 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
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

Determine how many mbytes are GC Android

 
Greenhorn
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
   

 
Bartender
Posts: 1868
81
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.
 
It's a beautiful day in this neighborhood - Fred Rogers. Tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic