Could not allocate dup blob fd

Viewed 1442

Imagem com os bitmaps personalizados renderizados

My app have approximately 1,500 markers on a map that are being shown through clusters so as not to overload the application. these bookmarks are currently shown as BitmapDescriptorFactory.defaultMarker ()

However, when I modify the code for each dot to show a custom bitmap with values on the markers, only a few devices have this error, among them LG K10 LTE and some Motorolas. Most appliances work normally.

When i use this function, before i finish rendering all 1500 markers, it crashes with the following error:

"Could not allocate dup blob fd."

In research on this error, it seems to me that this is a memory overflow and that I should store these markers in LRU cache, but I am not able to do this in conjunction with the clusters.

Has anyone had this or did you have an idea / suggestion to solve this problem?

The following is the bitmaps renderer code snippet:

public class OwnRendring extends DefaultClusterRenderer<MyItem> {

    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 = (item.getPublico() ? cfgCorPostoPublico : cfgCorPostoPrivado);
        String preço = item.getTitle().substring(item.getTitle().length() - 5);

        markerOptions.icon(BitmapDescriptorFactory.fromBitmap(createMarker(preço, cor)));
        super.onBeforeClusterItemRendered(item, markerOptions);

    }

    protected boolean shouldRenderAsCluster(Cluster cluster) {
        return cfgCluster && cluster.getSize() >= cfgClusterMin;
    }
}

@Override
public void onCameraIdle() {mClusterManager.cluster();}

private Bitmap createMarker(String text, int color) {
    View markerLayout = getLayoutInflater().inflate(R.layout.custom_marker, null);

    ImageView markerImage = markerLayout.findViewById(R.id.marker_image);
    TextView markerRating = 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;
}
1 Answers
Related