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

Last update: Aug 2, 2022

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.

GitHub

https://github.com/amitshekhariitbhu/GlideBitmapPool
Comments
  • 1. 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

    Reviewed by luckyjmcc at 2016-09-09 07:36
  • 2. 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.

    Reviewed by yiyinying at 2016-12-12 05:07
  • 3. 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

    Reviewed by Faradea at 2021-03-30 10:50
  • 4. 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.

    Reviewed by maxlab-code at 2019-09-12 10:09
  • 5. 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.

    Reviewed by kashifo at 2019-08-22 11:05
An Android transformation library providing a variety of image transformations for Glide.
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

Aug 11, 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.

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

Aug 18, 2022
Load images using Glide
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

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

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

Aug 1, 2019
An Android library for managing images and the memory they use.
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

Aug 9, 2022
An image loading and caching library for Android focused on smooth scrolling
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

Aug 12, 2022
A powerful image downloading and caching library for Android
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

Aug 12, 2022
Powerful and flexible library for loading, caching and displaying images on Android.
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

Aug 13, 2022
Photo picker library for android. Let's you pick photos directly from files, or navigate to camera or gallery.
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

Aug 17, 2022
An android image compression library.
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

Aug 14, 2022
An Android transformation library providing a variety of image transformations for Picasso
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

Aug 5, 2022
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

Sep 8, 2021
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 {

Aug 14, 2022
Andorid library that loads images asynchronously into cache using a thread pool
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

Feb 19, 2019
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! 🍻
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

Aug 17, 2022
Demonstration of Object Pool Design Pattern using Kotlin language and Coroutine
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

Apr 12, 2022
“Budgeter” is an optimized application for personal account management. Household account management is complicated.
“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

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

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

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

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)

Jan 18, 2022