OutOfMemoryError during findClosest

Dear friends, I’m developing an android app and I need to find the closest edge from latitude and longitude.

 Snap qr = hopper.getLocationIndex().findClosest(latitude, longitude, EdgeFilter.ALL_EDGES);

With small osm.pbf files (1/2 MB) everything was ok, now instead i load the following osm.pbf file

Sud Italy (more or less 250 MB) I’m getting this error:

E/AndroidRuntime: FATAL EXCEPTION: Timer-4
    Process: com.*.*, PID: 24530
    java.lang.OutOfMemoryError: Failed to allocate a 1284541136 byte allocation with 25149440 free bytes and 238MB until OOM, max allowed footprint 311732600, growth limit 536870912
        at com.graphhopper.storage.BaseGraph.fetchWayGeometry_(BaseGraph.java:400)
        at com.graphhopper.storage.BaseGraph.access$100(BaseGraph.java:43)
        at com.graphhopper.storage.BaseGraph$EdgeIteratorStateImpl.fetchWayGeometry(BaseGraph.java:864)
        at com.graphhopper.storage.index.LocationIndexTree.traverseEdge(LocationIndexTree.java:331)
        at com.graphhopper.storage.index.LocationIndexTree.lambda$findClosest$1$LocationIndexTree(LocationIndexTree.java:283)
        at com.graphhopper.storage.index.-$$Lambda$LocationIndexTree$IxB7P67mFqGhKi5xV92xZXcW4ZE.accept(Unknown Source:13)
        at com.graphhopper.storage.index.LineIntIndex.fillIDs(LineIntIndex.java:151)
        at com.graphhopper.storage.index.LineIntIndex.findEdgeIdsInNeighborhood(LineIntIndex.java:242)
        at com.graphhopper.storage.index.LocationIndexTree.findClosest(LocationIndexTree.java:280)
        at com.*.*.adapters.GraphhopperRouteAdapter.findClosestEdgeFromPoint(GraphhopperRouteAdapter.java:285)

I already added

android:largeHeap=“true”
android:hardwareAccelerated=“false”

in my AndroidManifest but nothing is changed. Any suggestion about this problem?

Thanks

Not sure what android:largeHeap="true" does, but for larger maps you might have to increase the heap size (use the Xmx parameter). This and some other tweaks are explained here: Host Your Own Worldwide Route Calculator With GraphHopper - GraphHopper Directions API

I added the following row in my gradle.properties:

org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -noverify

but the error is the same

The out of memory happens when app runs on Android (with GraphHopper)?
Then android:largeHeap is the best you can get.

Java Xmx and Gradle properties are for desktop.


And better use flexible graphs on Android.
Contraction hierarchies graphs have (memory) problems on Android.

Contraction hierarchies graphs have (memory) problems on Android.

The problem is not Contraction hierarchies, the problem is the broken/fake “Java” environment that Android provides: Provide workaround for OutOfMemoryError on Android · Issue #811 · graphhopper/graphhopper · GitHub

To my (potentially outdated) knowledge

  1. there is no mmap unmapping on Android and
  2. there is a per-process limit of the memory even if you only mmap the memory

Both can be fixed if you do the mmap via a native function

Flexible graphs (even large ones) worked fine on Android in the past.
(always with mmap data access)

And they allow more options on route requests.

But why should there be a problem with CH only? Did you test CH using a similar size and did it still crash?

We did test it at that time and the limit was purely related to some strange Android limit. In the end I found the per-process limit even in the Android source code.

When we used GraphHopper graphs in Kurviger,
we dropped the contraction hierarchies because they had memory problems.

(and less allowed parameters in route requests, e.g. heading)

We used flexible graphs, until Android scoped storage problem.

Ok, so you did not do tests regarding the graph size. I would just like to avoid the misinterpretation and CH might be just bigger in size resulting in these memory problems.

Graph size is important too.

Country graphs had more problems than city graphs.

In the past i also used large map like

Italy

that is five time more bigger than the actually. The problem is that now i need to call findClosest method on my new module , the fetchWayGeometry_ method is called with mode PILLAR_AND_ADJ and

 long geoRef = Helper.toUnsignedLong(this.store.getGeoRef(edgePointer));
            int count = 0;
            byte[] bytes = null;
            if (geoRef > 0L) {
                geoRef *= 4L;
                count = this.wayGeometry.getInt(geoRef);
                geoRef += 4L;
                bytes = new byte[count * this.nodeAccess.getDimension() * 4];
                this.wayGeometry.getBytes(geoRef, bytes, bytes.length);

and this snippet of code breaks the app

Can you give me how to enable flex mode on graphhopper 5.0 version, what we need to enable/disable/change?

Thanks

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.