Some test text!

Search
Hamburger Icon

Android / FAQ / How do I reduce memory consumption for PDFViewCtrl?

Reduce memory consumption

Change render cache size

In order to achieve smoother viewing experience, PDFViewCtrl keeps certain amount of invisible content. However, keeping invisible content increases memory usage. Android sets an upper bound on the VM heap size allowed for an app. By default, PDFViewCtrl is set to use a quarter of maximum VM heap size for keeping visible and invisible content. Based on the memory footprint of your app, you may want to customize it.

To customize the memory usage:

long allowedMax = Runtime.getRuntime().maxMemory() / (1024 * 1024);
 //should NOT use close to allowedMax
pdfViewCtrl.setRenderedContentCacheSize((long) (allowedMax * 0.25));

where pdfViewCtrl is an instance of PDFViewCtrl.

If you want to minimize the heap memory usage at the cost of viewing experience quality, you can set allowed_max to 0. PDFViewCtrl will not keep any invisible content.
setRenderedContentCacheSize(long) only controls the memory usage of VM heap size by PDFViewCtrl, but not the native memory that PDFViewCtrl might use.

Prevent out of memory when rotating device

Question:

We are experiencing a lot of out of memory errors when rotating the device multiple times. Since the Activity is destroyed while rotating, we get a new (quite heavy) PDFViewCtrl every time we rotate the device.

Answer:

PDFViewCtrl can handle rotation properly, it is recommended that you configure your activity to handle configuration changes. This way the view will not be recreated and it will be resized accordingly.

  1. In your app AndroidManifest.xml file, add android:configChanges to your activity tag.

    <activity
        android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize"
        >
      </activity>
  2. Override onConfigurationChanged() in your activity:

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        if (mPdfViewCtrl != null) {
            mPdfViewCtrl.onConfigurationChanged(newConfig);
        }
    }

    where mPdfViewCtrl is an instance of PDFViewCtrl.

Increase Android heap size

On Android 3.0 and above, you can also increase the allowed heap size of an app.

In your app AndroidManifest.xml file, add the android:largeHeap="true" attribute to the <application> tag:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  >
  <application
    android:largeHeap="true"
    >
  </application>

</manifest>

Trial setup questions? Ask experts on Discord
Need other help? Contact Support
Pricing or product questions? Contact Sales