Log free heap memory

pull/156/head
M66B 6 years ago
parent 36c691eb25
commit df5376a860

@ -229,6 +229,7 @@ public class ApplicationEx extends Application {
public boolean run(@NonNull Error error) {
error.addToTab("extra", "installer", installer == null ? "-" : installer);
error.addToTab("extra", "fingerprint", fingerprint);
error.addToTab("extra", "free", Helper.getFreeMemMb());
return true;
}
});

@ -614,4 +614,15 @@ public class Helper {
bundle.writeToParcel(p, 0);
return p.dataSize();
}
static long getFreeMem() {
Runtime rt = Runtime.getRuntime();
long used = (rt.totalMemory() - rt.freeMemory());
long max = rt.maxMemory();
return (max - used);
}
static int getFreeMemMb() {
return (int) (getFreeMem() / 1024L / 1024L);
}
}

@ -152,21 +152,17 @@ public class ViewModelMessages extends ViewModel {
owner.getLifecycle().addObserver(new LifecycleObserver() {
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
public void onDestroyed() {
Log.i("Destroy model " + viewType);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean cache = prefs.getBoolean("cache_lists", true);
Runtime rt = Runtime.getRuntime();
long used = (rt.totalMemory() - rt.freeMemory());
long max = rt.maxMemory();
long free_mb = (max - used) / 1024L / 1024L;
int free_mb = Helper.getFreeMemMb();
boolean lowmem = (free_mb < LOW_MEM_MB);
if (viewType == AdapterMessage.ViewType.THREAD || !cache || lowmem) {
Log.i("Remove model " + viewType +
Log.i("Destroy model " + viewType +
" cache=" + cache + " lowmem=" + lowmem + " free=" + free_mb + " MB");
if (viewType == AdapterMessage.ViewType.THREAD || !cache || lowmem) {
Log.i("Remove model " + viewType);
remove(viewType);
}

Loading…
Cancel
Save