elsa icon indicating copy to clipboard operation
elsa copied to clipboard

java.lang.OutOfMemoryError

Open gilshallem opened this issue 6 years ago • 0 comments

Getting java.lang.OutOfMemoryError when initilize on android:


            ElsaSerializerBase.Deserializer<Bitmap> deser = new ElsaSerializerBase.Deserializer<Bitmap>() {
                @Override
                public Bitmap deserialize(DataInput in, ElsaStack objectStack) throws IOException {

                    int bufferLength = in.readInt();

                    byte[] byteArray = new byte[bufferLength];
                    in.readFully(byteArray, 0, bufferLength);
                    return BitmapFactory.decodeByteArray(byteArray, 0, bufferLength);
                }
            };



            ElsaSerializerBase.Serializer<Bitmap> ser = new ElsaSerializerBase.Serializer<Bitmap>() {
                @Override
                public void serialize(DataOutput out, Bitmap bitmap, ElsaStack objectStack) throws IOException {
                    ByteArrayOutputStream stream = new ByteArrayOutputStream();
                    bitmap.compress(Bitmap.CompressFormat.JPEG, 80, stream);

                    byte[] byteArray = stream.toByteArray();

                    out.writeInt(byteArray.length);
                    out.write(byteArray);
                }
            };

            serializer = new ElsaMaker()
                    .registerSerializer(BITMAP_HEADER, Bitmap.class, ser)
                    .registerDeserializer(BITMAP_HEADER, deser)
                    .make();

java.lang.OutOfMemoryError: Failed to allocate a 953893208 byte allocation with 6291456 free bytes and 507MB until OOM, max allowed footprint 10774144, growth limit 536870912

gilshallem avatar Oct 06 '18 06:10 gilshallem