Skip to content

Commit 6775842

Browse files
author
Peter
committed
trying to fix graphhopper#283, Work around System.gc() calls for mobile
1 parent f665166 commit 6775842

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

core/src/main/java/com/graphhopper/storage/GHDirectory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public void clear()
150150
removeDA(da, da.getName(), false);
151151
}
152152
if (mmapDA != null)
153-
mmapDA.cleanHack();
153+
Helper.cleanHack();
154154
map.clear();
155155
}
156156

core/src/main/java/com/graphhopper/storage/MMapDataAccess.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ protected boolean mapIt( long offset, long byteCount, boolean clearNew )
135135
{
136136
newSegments = segmentsToMap;
137137
clean(0, segments.size());
138-
cleanHack();
138+
Helper.cleanHack();
139139
segments.clear();
140140
} else
141141
{
@@ -183,7 +183,7 @@ private ByteBuffer newByteBuffer( long offset, long byteCount ) throws IOExcepti
183183
{
184184
ioex = tmpex;
185185
trial++;
186-
cleanHack();
186+
Helper.cleanHack();
187187
try
188188
{
189189
// mini sleep to let JVM do unmapping
@@ -293,13 +293,7 @@ void close( boolean forceClean )
293293
segments.clear();
294294
Helper.close(raFile);
295295
if (forceClean)
296-
cleanHack();
297-
}
298-
299-
void cleanHack()
300-
{
301-
// trying to force the release of the mapped ByteBuffer
302-
System.gc();
296+
Helper.cleanHack();
303297
}
304298

305299
@Override
@@ -427,7 +421,7 @@ public void trimTo( long capacity )
427421
}
428422

429423
clean(remainingSegNo, segments.size());
430-
cleanHack();
424+
Helper.cleanHack();
431425
segments = new ArrayList<ByteBuffer>(segments.subList(0, remainingSegNo));
432426

433427
try
@@ -454,7 +448,7 @@ boolean releaseSegment( int segNumber )
454448

455449
Helper.cleanMappedByteBuffer(segment);
456450
segments.set(segNumber, null);
457-
cleanHack();
451+
Helper.cleanHack();
458452
return true;
459453
}
460454

core/src/main/java/com/graphhopper/util/Helper.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,15 @@ public Object run() throws Exception
405405
}
406406
}
407407

408+
/**
409+
* Trying to force the release of the mapped ByteBuffer. See
410+
* http://stackoverflow.com/q/2972986/194609 and use only if you know what you are doing.
411+
*/
412+
public static void cleanHack()
413+
{
414+
System.gc();
415+
}
416+
408417
public static String nf( long no )
409418
{
410419
// I like french localization the most: 123654 will be 123 654 instead

0 commit comments

Comments
 (0)