Android memory leak with Glide

前端 未结 3 1840
北海茫月
北海茫月 2021-02-09 01:40

I have an activity which loads pictures in ImageViews with glide. Here is a sample of my glide code:

    Glide.with(ImageVOne.getContext())
            .load(geo         


        
3条回答
  •  被撕碎了的回忆
    2021-02-09 01:55

    Here is a sample of my glide code : Glide.with(ImageVOne.getContext()) .load(geoInfo.getPhotoUrl1()) .skipMemoryCache(true) .priority(Priority.NORMAL) .into(ImageVOne);

    Your problem is most likely stemming from the this call: Glide.with(ImageVOne.getContext()).... You don't want to do this because View.getContext() returns the Application Context. By using Glide with the Application Context you're telling Glide to follow the application's lifecycle and not your Activity's lifecycle, resulting in the Glide image loads never being cancelled or cleared when you back out of said Activity.

    So instead use: Glide.with(MyActivity.this)....

    Note: Always tie your Glide load requests to the nearest possible lifecycle to ensure that Glide follows the lifecycle that it's being used in

提交回复
热议问题