Hello!
My app uses Google Maps library, to eventually show a map with two markers, animated to bounds every time it appears.
My problem is that every time the map is shown and being animated, I have a memory increase by 45-70 MB that they don't be released after marker1.Remove, marker2.Remove and mfragment.Clear.
The result is that after some hours the app crashes with OutOfMemory!
UPDATE:
The memory is being increased even if I move the map manually!
What should I do?
The code I use:
Where setMMarkers (or setLMarkers) is:
And when I hide the map I do:
Thank you in advance!
My app uses Google Maps library, to eventually show a map with two markers, animated to bounds every time it appears.
My problem is that every time the map is shown and being animated, I have a memory increase by 45-70 MB that they don't be released after marker1.Remove, marker2.Remove and mfragment.Clear.
The result is that after some hours the app crashes with OutOfMemory!
UPDATE:
The memory is being increased even if I move the map manually!
What should I do?
The code I use:
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private GMapEx As GoogleMapsExtras
End Sub
B4X:
private Sub loadMarkers(mMap As GoogleMap,mMapName As String)
Private mOp As MarkerOptions
mOp.Initialize
Private bDs As BitmapDescriptor
Private bDf As BitmapDescriptorFactory
Private pin As Bitmap
Private AR As AndroidResources
Private SPin As BitmapDrawable
Private CPin As BitmapDrawable
SPin = AR.GetApplicationDrawable("tcar")
CPin = AR.GetApplicationDrawable("passpin")
pin = CPin.Bitmap
bDs = bDf.FromBitmap(pin)
mOp.Icon(bDs)
mOp.Anchor(mOp.GetAnchorU,mOp.GetAnchorV)
mOp.Position2(Starter.routeLat,Starter.routeLon)
Select mMapName
Case "M"
M2C = GMapEx.AddMarker(mMap, mOp)
Case "L"
M2L = GMapEx.AddMarker(mMap, mOp)
End Select
pin = SPin.Bitmap
bDs = bDf.FromBitmap(pin)
mOp.Icon(bDs)
mOp.Anchor(mOp.GetAnchorU,mOp.GetAnchorV/2)
mOp.Position2(Starter.gpslat,Starter.gpslon)
Private CLoc As Location
CLoc.Initialize2(Starter.routeLat,Starter.routeLon)
mOp.Rotate(Starter.gpsLoc.BearingTo(CLoc))
Select mMapName
Case "M"
M1C = GMapEx.AddMarker(mMap, mOp)
setMMarkers
Case "L"
M1L = GMapEx.AddMarker(mMap, mOp)
setLMarkers
End Select
End Sub
B4X:
private Sub setMMarkers
Private LatLongB As LatLngBoundsBuilder
LatLongB.Initialize
LatLongB.Include(M1C.Position)
LatLongB.Include(M2C.Position)
Private camFactory As CameraUpdateFactory
Private camBounds As CameraUpdate
camBounds = camFactory.NewLatLngBounds2(LatLongB.Build,pnlMapCms.GetView(0).Width,pnlMapCms.GetView(0).Height,90)
GMapEx.AnimateCamera3(GCMap,camBounds,100,Null)
End Sub
B4X:
private Sub removeMarkers(rGMapName As String)
Select rGMapName
Case "G"
If Marker2.IsInitialized Then
Marker2.Remove
Marker2 = Null
End If
Case "M"
GCMap.Clear
If M1C.IsInitialized Then M1C.Remove
M1C = Null
If M2C.IsInitialized Then M2C.Remove
M2C = Null
If Marker2.IsInitialized Then Marker2.Remove
Marker2 = Null
Case "L"
GLMap.Clear
If M1L.IsInitialized Then M1L.Remove
M1L = Null
If M2L.IsInitialized Then M2L.Remove
M2L = Null
If Marker2.IsInitialized Then Marker2.Remove
Marker2 = Null
End Select
Private r As Reflector
r.RunStaticMethod("java.lang.System", "gc", Null, Null)
r = Null
Private markGEx As MarkerExtras
markGEx.SetRotation(Marker1,0)
End Sub
Last edited: