Lect0r / osmdroid

Automatically exported from code.google.com/p/osmdroid
0 stars 0 forks source link

Out of memory when rotating display #54

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Copied from issue 27 comment 18 point 4 and comment 24:

If you turn the display from horizontal to vertical or vice versa, the cache 
seems unnecessarily to fetch everything again.

I can reproduce the OutOfMemory error very easily by rotating my screen about 
10 times.

It seems after a screen rotation all the tiles are reloaded into memory, but 
the garbage collector hasn't freed the memory from 
the old tiles yet, which eventually leads to an OutOfMemory error.

Original issue reported on code.google.com by neilboyd on 27 May 2010 at 8:51

GoogleCodeExporter commented 9 years ago
Did some debugging.

When rotating the activitiy is "relaunched".

It means onPause is called on the old activity and a new activity instance is 
created
and initialized. 
Presumably the old activity is up for garbage collection, unless there are some
pointers that point to it or some subparts (the tile cache).

I don't know a good way to carry over the tile cache between activities.

Original comment by viesturz on 27 May 2010 at 10:26

GoogleCodeExporter commented 9 years ago
I don't think there is a good way to carry over the tile cache, but maybe there 
is a
way to call recycle() on the old image tiles when the old activity is no longer 
needed.

I know the docs say calling recycle() manually is not needed as it is called
automatically by the garbage collector, but I think the issue here is that more 
free
memory is required before the garbage collector has run. 
Calling recycle() would clear the used memory manually, immediately freeing the 
image
memory, without having to wait for the GC.

Maybe that would already help ?

Original comment by h...@navitell.com on 27 May 2010 at 10:35

GoogleCodeExporter commented 9 years ago
I forgot to mention: I tried forcing a recycle of the image tiles, but I 
couldn't
figure out how to remove them from the tile cache. I ended up with the memory 
being
recycled, but the overlay still tried to use the tiles on the next screen 
redraw,
resulting in gray areas on the map.
What is the proper way of invalidating a tile in the tile cache, so it is 
re-read
from memory when needed again ?

Original comment by h...@navitell.com on 27 May 2010 at 10:38

GoogleCodeExporter commented 9 years ago
Probably the view is holding a reference back to the activity that created it. 
The context is the usual culprit. Passing 
getApplicationContext() instead of "this" for the context parameter often 
helps.  But this also depends on the activity that's using 
the view.

For example, in SampleWithMinimapItemizedoverlay, change
mOsmv = new OpenStreetMapView(this, OpenStreetMapRendererInfo.MAPNIK);
to
mOsmv = new OpenStreetMapView(getApplicationContext(), 
OpenStreetMapRendererInfo.MAPNIK);

That's just a suggestion. I haven't looked into this issue.

Original comment by neilboyd on 27 May 2010 at 10:59

GoogleCodeExporter commented 9 years ago
I tried the above suggestion (passing application context in stead of 
activity), but
it doesn't seem to help. Still the same out of memory error after about 10 
screen
rotations.

Original comment by h...@navitell.com on 30 May 2010 at 2:15

GoogleCodeExporter commented 9 years ago
The Activity.getLastNonConfigurationInstance() method might be what you are 
looking for. It allows you to pass claimed resources (e.g. memory, 
IO-references) between orientation switches lifecyle event.

Then a relaunched app doesnt need to reload everything.

Original comment by rcgr...@gmail.com on 13 Jun 2010 at 11:58

GoogleCodeExporter commented 9 years ago
Issue 57 has been merged into this issue.

Original comment by neilboyd on 18 Jun 2010 at 3:13

GoogleCodeExporter commented 9 years ago
After rotating the screen over 50 times on my 2.2 Nexus One it was as 
responsive as it was at the beginning. And the same on my 1.6 G1.

I think it's time to close this issue.

Original comment by neilboyd on 7 Jul 2010 at 5:09

GoogleCodeExporter commented 9 years ago

Original comment by neilboyd on 10 Sep 2010 at 2:32

GoogleCodeExporter commented 9 years ago
I have the same problem. After a few orientation changes or after pressing back 
button and restarting a couple of times the app crashes on HTC Desire. Easily 
repeatable.

Original comment by toreleve...@gmail.com on 20 Jun 2011 at 12:32

GoogleCodeExporter commented 9 years ago
I have the same issue. it crashes both on the emulator and on galaxy (1.5)

Original comment by ori.kle...@gmail.com on 31 Jul 2011 at 2:05