Win a copy of Terraform in Action this week in the Cloud 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic