Skip to content

Android OutOfMemoryError occurs when readTiff for 400MB tif file #31

Closed

Description

@songhu42

Please fill out as much known and relevant information as possible.

Version Information:

  • TIFF Java Version: 2.0.2
  • TIFF Java Source: Central Repository
  • IDE Name & Version: Android Studio 3.2.1
  • Maven Version: (mvn -version) : gradle:3.2.1
  • Java Version: (java -version) : Android-26
  • Platform & OS: Android
  • Other Relevant Libraries:

Expected Results:

  • What did you expect to happen?
    Open the big tif file : TiffReader.readTiff(tiffFile)

Observed Results:

  • What happened instead?
    AndroidRuntime: FATAL EXCEPTION: Thread-19
    java.lang.OutOfMemoryError: Failed to allocate a 536870928 byte allocation with 25165824 free bytes and 234MB until OOM, target footprint 316450016, growth limit 536870912

  • How often does this occur? Always

Output:

  • Any logs, errors, or output messages?
    java.lang.OutOfMemoryError: Failed to allocate a 536870928 byte allocation with 25165824 free bytes and 234MB until OOM, target footprint 316450016, growth limit 536870912
    at java.util.Arrays.copyOf(Arrays.java:3161)
    at java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:118)
    at java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:93)
    at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:153)
    at mil.nga.tiff.io.IOUtils.copyStream(IOUtils.java:104)
    at mil.nga.tiff.io.IOUtils.streamBytes(IOUtils.java:83)
    at mil.nga.tiff.io.IOUtils.fileBytes(IOUtils.java:67)
    at mil.nga.tiff.TiffReader.readTiff(TiffReader.java:51)
    at mil.nga.tiff.TiffReader.readTiff(TiffReader.java:35)
    at com.mvsoftech.mvgis.forestServices.DemFinder$2.run(DemFinder.java:49)
    at java.lang.Thread.run(Thread.java:919)

Steps to Reproduce:

  1. just run app in mobile

Relevant Code:

// Code to reproduce the problem?
TIFFImage tiffImage = TiffReader.readTiff(tiffFile);

Test Files:

  • Links to any files needed for testing?

Additional Information:

  • Any additional configuration, data, or information that might help with the issue?
  • Thank you If you can fix it

Activity

  1. bradh commented on Jun 11, 2021

    @bradh
    Contributor

    Can you provide file(s) that demonstrate the problem? Even the results of a gdalinfo dump may help.

    Also, what do you have set for your Dalvik heap size to?

  2. bosborn commented on Jun 21, 2021

    @bosborn
    Contributor

    This implementation loads the entire tiff file into memory for raster random read access. Your reported error occurred attempting to copy the file into memory. Allocation of ~537mb with a growth limit of ~537mb.

    Try increasing the heap size.

  3. locked and limited conversation to collaborators on Jun 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions