Failed to allocate dup blob fd: IconGenerator with thousands of markers throws an exception

My application has 1.5 thousand markers, showed cluster clusters.

It actually works fine with default markers, but I want to use vector bitmaps and rendering markers with text (price of a gas station), for example:

! [enter image description here

Before completing the rendering markers, this exception occurs: "Failed to allocate dup blob fd."

I think this is some kind of memory overflow, but I do not know how to solve it. Does anyone know how to solve this problem or is there another suggestion on how to manage so many markers?

Note. I already use marker clusters.

Note. This issue only occurs on some Motorola and LG devices. In most devices it works fine. Some code:

public class OwnRendring extends DefaultClusterRenderer<MyItem> { public OwnRendring(Context context, GoogleMap map, ClusterManager<MyItem> clusterManager) { super(context, map, clusterManager); } protected void onBeforeClusterItemRendered(MyItem item, MarkerOptions markerOptions) { markerOptions.snippet(item.getSnippet()); markerOptions.title(item.getTitle()); markerOptions.anchor(0.33f, 1f); markerOptions.infoWindowAnchor(0.33f,0f); int cor; if (item.getPublico()) { cor=cfgCorPostoPublico; } else { cor=cfgCorPostoPrivado; } String preço = item.getTitle().substring(item.getTitle().length() - 5); if (Objects.equals(preço, "0,000")) { preço=""; } Bitmap bitmap = createStoreMarker(preço, cor); markerOptions.icon(BitmapDescriptorFactory.fromBitmap(bitmap)); super.onBeforeClusterItemRendered(item, markerOptions); } protected boolean shouldRenderAsCluster(Cluster cluster) { // if markers < cfgClusterMin then not clustering return cfgCluster && cluster.getSize() >= cfgClusterMin; } } private Bitmap createStoreMarker(String text, int color) { View markerLayout = getLayoutInflater().inflate(R.layout.custom_marker, null); ImageView markerImage = (ImageView) markerLayout.findViewById(R.id.marker_image); TextView markerRating = (TextView) markerLayout.findViewById(R.id.marker_text); markerImage.setImageResource(R.drawable.pin_shadow); markerImage.clearColorFilter(); markerImage.getDrawable().mutate().setColorFilter(color, PorterDuff.Mode.MULTIPLY ); markerRating.setText(text); markerLayout.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); markerLayout.layout(0, 0, markerLayout.getMeasuredWidth(), markerLayout.getMeasuredHeight()); final Bitmap bitmap = Bitmap.createBitmap(markerLayout.getMeasuredWidth(), markerLayout.getMeasuredHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); markerLayout.draw(canvas); return bitmap; } 
+5
source share

Source: https://habr.com/ru/post/1268075/


All Articles