Glide Bitmap Pool is a memory management library for reusing the bitmap memory

Overview

Glide Bitmap Pool

Mindorks Mindorks Community Mindorks Android Store Open Source Love License

About Glide Bitmap Pool

Glide Bitmap Pool is a memory management library for reusing the bitmap memory. As it reuses bitmap memory , so no more GC calling again and again , hence smooth running application. It uses inBitmap while decoding the bitmap on the supported android versions. All the version use-cases has been handled to optimize it better.

Why use this library ?

An Image heavy Application decodes many images , so there will be continuous allocation and deallocation of memory in application , and that results in very frequent calling of GC(Garbage Collector). And finally because of very frequent calling of GC , the application UI freezes. Use Bitmap pool to avoid continuous allocation and deallocation of memory in application and reduce GC overhead that will result in smooth running application. Suppose we have to load few bitmap in Android Application. When we load bitmapOne , it will allocate the memory for bitmapOne. Then if we don’t need bitmapOne , do not recycle bitmap (as if you recycle, it will make GC to be called) , so use this bitmapOne as an inBitmap for bitmapTwo so that , the same memory can be reused for bitmapTwo. In this way , we can avoid continuous allocation and deallocation of memory in application and reduce GC overhead. But the problem is that there are few restrictions as android version less than Honeycomb does not supports it , few android version less than Kitkat only when we use inSampleSize = 1 , above that it supports completely and few other issues. So , all these types of cases are handled in this library

GET RID OF : GC_FOR_ALLOC freed 1568K, 23% free 37664K/48844K, paused 141ms, total 143ms - (whenever you see this log , your application is lagging)

Requirements

Glide Bitmap Pool can be included in any Android or Java application.

Glide Bitmap Pool supports Android 2.3 (Gingerbread) and later.

Using Glide Bitmap Pool in your application

Add this in your build.gradle

compile 'com.amitshekhar.android:glide-bitmap-pool:0.0.1'

Then initialize it in onCreate() Method of application class, :

GlideBitmapPool.initialize(10 * 1024 * 1024); // 10mb max memory size

Decoding the bitmap from file path

Bitmap bitmap = GlideBitmapFactory.decodeFile(filePath);

Decoding the bitmap from resources

Bitmap bitmap = GlideBitmapFactory.decodeResource(getResources(), R.drawable.testImage);

Decoding the down sample bitmap

Bitmap bitmap = GlideBitmapFactory.decodeFile(filePath,100,100);

Making the bitmap available for recycle or reuse

GlideBitmapPool.putBitmap(bitmap);

Getting the empty bitmap from the pool

Bitmap bitmap = GlideBitmapPool.getBitmap(width, height, config);

Clearing or Trimming Memory

GlideBitmapPool.clearMemory();
GlideBitmapPool.trimMemory(level);

Migrating to Glide Bitmap Pool

// ------   decoding -------

// old code 
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.test1);

// new code 
Bitmap bitmap = GlideBitmapFactory.decodeResource(getResources(), R.drawable.test1);

// ------   recycling ------- 

// old code
bitmap.recycle();

// new code
GlideBitmapPool.putBitmap(bitmap);

//  ------   creating a bitmap -------

// old code 
Bitmap bitmap = Bitmap.create(width, height, config);

// new code
Bitmap bitmap = GlideBitmapPool.getBitmap(width, height, config);

Important

// Do not use bitmap.recycle();
// use GlideBitmapPool.putBitmap(bitmap); as it will put bitmap in the pool for further reuse.

// Do not use Bitmap.create(width, height, config);
// use GlideBitmapPool.getBitmap(width, height, config); as it returns bitmap from the pool that can be reused.

Find this project useful ? ❤️

  • Support it by clicking the button on the upper right of this page. ✌️

Credits and references

TODO

  • More Optimization with further updates.

Check out another awesome library for fast and simple networking in Android.

Another awesome library for debugging databases and shared preferences.

Check out Mindorks awesome open source projects here

Contact - Let's become friend

License

   Copyright (C) 2016 Amit Shekhar
   Copyright (C) 2011 Android Open Source Project

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

Contributing to Glide Bitmap Pool

All pull requests are welcome, make sure to follow the contribution guidelines when you submit pull request.

Comments
  • what is the difference ?

    what is the difference ?

    what is the difference between you package com.glidebitmappool.internal.* and Glide's package com.bumptech.glide.load.engine.bitmap_recycle.* ? except Util.java

    opened by luckyjmcc 8
  • have a bug

    have a bug

    android 4.2.2 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK) { Uri imageFileUri=data.getData(); Display currentDisplay=getWindowManager().getDefaultDisplay(); int dw=currentDisplay.getWidth(); int dh = currentDisplay.getHeight()/2-100; try { //Bitmap bmp = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageFileUri)); Bitmap bmp = GlideBitmapFactory.decodeStream( getContentResolver().openInputStream(imageFileUri),200,200); chosenImageView.setImageBitmap(bmp); } catch (FileNotFoundException e) { e.printStackTrace(); } } } bmp is null.

    opened by yiyinying 0
  • Migrate from JCenter

    Migrate from JCenter

    JCenter will be shouted down - https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/. JCenter repository will keep serving packages for 12 months until February 1st 2022

    opened by Faradea 1
  • Fixing returning null bitmap by reiteration of stream actions

    Fixing returning null bitmap by reiteration of stream actions

    After decoding a stream there was errors of further decoding stream calls because the reading position of a stream was not reseted.

    Added function "rewindStream" which safely reset stream for further usage.

    opened by maxlab-code 1
  • How to replace other methods of Bitmap.create?

    How to replace other methods of Bitmap.create?

    Hi, First of all you've done a great job, it's very useful. It seems this library only supports this method Bitmap.create(width, height, config)

    I am using this method Bitmap createBitmap(Bitmap source, int x, int y, int width, int height)

    Can you please tell me how to replace the above method?

    Thanks Kashif.

    opened by kashifo 0
Releases(v0.0.1)
Owner
AMIT SHEKHAR
Always Learning and Sharing | Co-Founder @ MindOrks, AfterAcademy, CuriousJr
AMIT SHEKHAR
An Android transformation library providing a variety of image transformations for Glide.

Glide Transformations An Android transformation library providing a variety of image transformations for Glide. Please feel free to use this. Are you

Daichi Furiya 9.7k Dec 30, 2022
🍂 Jetpack Compose image loading library which can fetch and display network images using Glide, Coil, and Fresco.

?? Jetpack Compose image loading library which can fetch and display network images using Glide, Coil, and Fresco.

Jaewoong Eum 1.4k Jan 2, 2023
Load images using Glide

Glide_Demo Load images using Glide Image used private val image = "https://cdn.pixabay.com/photo/2018/05/03/21/49/android-3372580_1280.png" Add Glide

Daniel Kago K 0 Nov 1, 2021
Bitmap decoder, handle resize & quality & compress stuff following user's configurations.

SoBitmap SoBitmap is not an ImageLoader, it born for process single bitmap. Some conditions, we want a image displayed in some limit, such as the max

Kevin Liu 87 Aug 1, 2019
Bitmap decoder, handle resize & quality & compress stuff following user's configurations.

SoBitmap SoBitmap is not an ImageLoader, it born for process single bitmap. Some conditions, we want a image displayed in some limit, such as the max

Kevin Liu 87 Aug 1, 2019
An Android library for managing images and the memory they use.

Fresco Fresco is a powerful system for displaying images in Android applications. Fresco takes care of image loading and display, so you don't have to

Facebook 16.9k Jan 8, 2023
An image loading and caching library for Android focused on smooth scrolling

Glide | View Glide's documentation | 简体中文文档 | Report an issue with Glide Glide is a fast and efficient open source media management and image loading

Bump Technologies 33.2k Jan 7, 2023
A powerful image downloading and caching library for Android

Picasso A powerful image downloading and caching library for Android For more information please see the website Download Download the latest AAR from

Square 18.4k Jan 6, 2023
Powerful and flexible library for loading, caching and displaying images on Android.

Universal Image Loader The great ancestor of modern image-loading libraries :) UIL aims to provide a powerful, flexible and highly customizable instru

Sergey Tarasevich 16.8k Jan 8, 2023
Photo picker library for android. Let's you pick photos directly from files, or navigate to camera or gallery.

ChiliPhotoPicker Made with ❤️ by Chili Labs. Library made without DataBinding, RxJava and image loading libraries, to give you opportunity to use it w

Chili Labs 394 Jan 2, 2023
An android image compression library.

Compressor Compressor is a lightweight and powerful android image compression library. Compressor will allow you to compress large photos into smaller

Zetra 6.7k Jan 9, 2023
An Android transformation library providing a variety of image transformations for Picasso

Picasso Transformations An Android transformation library providing a variety of image transformations for Picasso. Please feel free to use this. Are

Daichi Furiya 1.7k Jan 5, 2023
Library to handle asynchronous image loading on Android.

WebImageLoader WebImageLoader is a library designed to take to hassle out of handling images on the web. It has the following features: Images are dow

Alexander Blom 102 Dec 22, 2022
Compose Image library for Kotlin Multiplatform.

Compose ImageLoader Compose Image library for Kotlin Multiplatform. Setup Add the dependency in your common module's commonMain sourceSet kotlin {

Seiko 45 Dec 29, 2022
Andorid library that loads images asynchronously into cache using a thread pool

AndroidImageLoader AndroidImageLoader is a fork of the Image Loader component in libs-for-android. The AndroidImageLoader is an Android library that h

David Wu 63 Feb 19, 2019
Demonstration of Object Pool Design Pattern using Kotlin language and Coroutine

Object Pool Design Pattern with Kotlin Demonstration of Thread Safe Object Pool Design Pattern using Kotlin language and Coroutine. Abstract The objec

Enes Kayıklık 7 Apr 12, 2022
Big image viewer supporting pan and zoom, with very little memory usage and full featured image loading choices. Powered by Subsampling Scale Image View, Fresco, Glide, and Picasso. Even with gif and webp support! 🍻

BigImageViewer Big image viewer supporting pan and zoom, with very little memory usage and full featured image loading choices. Powered by Subsampling

Piasy 3.9k Dec 30, 2022
“Budgeter” is an optimized application for personal account management. Household account management is complicated.

Budgeter Links ?? Open-Source Library MVVM-Architecture Viewmodel-LiveData Room Database Dependency Injection-Hilt Coroutines Things we used while mak

Aditya Cheke 0 Dec 20, 2021
Android-kotlin-lifecycles-management - LifeCycles Management Techniques

Activity Lifecycle - DessertPusher This is the toy app for lesson 4 of the Andro

Jeliel Augusto Mota 0 Jan 8, 2022
Show worldwide headline. API/Glide library/recycler view/volley library/kotlin/xml/ chrome custom tabs

Show worldwide headline. API/Glide library/recycler view/volley library/kotlin/xml/ chrome custom tabs. -> you can click on headline and it will open an article of that news in the app(no need to go to chrome or any browser)

SUMIT KUMAR 5 Nov 28, 2022