android.widget.ProgressBar memory leak?

I'm finally getting close to release, and have started to look at potential memory leaks. I think everything looks ok, EXCEPT for I seem to be leaking a ProgressBar every time I use a particular screen.

It's very strange, and I've Googled around but haven't found anything. Any ideas?

Thanks,

Answers

  • jezhjezh Member, Xamarin Team Xamurai

    According to the information you gave, I can't give the exact solution. But You could try to find whether somewhere has used the instance of the ProgressBar, and couldn't release the instance because of some reasons.

    Here are some links you can refer to:

    https://xamarinhelp.com/tracking-memory-leaks-xamarin-profiler/
    https://xamarinhelp.com/tracking-memory-leaks-xamarin-profiler-part-2/

  • PetiephantPetiephant Member ✭✭

    I can't use the Xamarin Profiler as I don't have an Enterprise licence; I've just been using DDMS/MAT.

    It's not very complicated however. The ProgressBar is defined in the XML for the Fragment, then it waits for a background task to complete and then changes the visibility to Gone. The background task is in a separate layer outside of the Fragment so no references are stored to it, the Fragment simply subscribes (and correctly unsubscribes as well) to events and then updates the UI accordingly. I suspect I would see the whole Fragment leaking if I had bigger problems. A ~150KB leak every time is still significant though, and because users can use this screen many times, this will eventually lead to OOM. I have, in fact seen this myself while testing. If I take out the ProgressBar, then the leak goes away.

    I also have a separate admin app. The setup is different, but the layout is even simpler; just a ProgressBar on the root of the Activity. After a quick test however it does the same thing, if you enter and leave the Activity many times a whole load of ProgressBar come up in the MAT.

    Sounds like an internal problem to me? I'm not using this any differently to any other widget, and they don't leak. Urgh ...

    UPDATE:

    If you drill down in the MAT it appears to be the bitmaps that aren't getting released properly? After running it again I also noticed that both my Splash and Boot Activity were in the list as well (I haven't seen this before). Drilling down in them it also appears that my logo isn't being released, even well after those have finished and are not on the back stack. I also forced a GC and they didn't disappear.

    Maybe there's actual a serious problem somewhere? It all seems to relate to Bitmap memory, however in these instances I'm not handling this myself, it's either through a standard ImageView or ProgressBar. All other images in my app are loaded through Glide, which doesn't appear to have any problems.

Sign In or Register to comment.